Max element of the Array | Min element of Array | Array max Vs Min | Maximum and Minimum component of Array



//Written in Java By Syed Ali Haider
//Student of The Hajvery University,Lahore, Pakistan.
//Don't remove these lines for legal use
//For more Please contact us.

import java.util.Scanner; // for get input from user
public class Array_java { //class begin
      
public static void main(String[] args) { // main function begin
      
      
       Scanner input = new Scanner (System.in); // object for get input from keyboard


      
       System.out.print("How many component do you want to enter: ");
       int size = input.nextInt(); // decide how component will be in the arry
      
      
       int item [] = new int [size] ; // syntax line
      
       System.out.println("\n");
      
       //for get multiple input till entered limit comes
              for (int i=0; i<size ; i++)
       {

       System.out.print("Please enter the component No: " + (i+1) + " here: ");
       item [i] = input.nextInt();
       }
      
       System.out.println("\n");
      
       // print the component of array
int coun=0;
              for (int i=0; i< item.length ; i++)
       {
       System.out.println( i+1 + "-Component :" + item[i]);
       coun++;
       }
       System.out.println("\n");
       if (coun == 0)
       System.out.println("There is no component in array"); 
      
       //for check the maximum value in the array
       int max =0;         
              for (int i=0; i<item.length; i++)
       {
              if (item[i] > max)
                     max= item[i];
       }
      
       System.out.println("The max component is: " + max);
             
       // for check the minimum value in the array
       int min=1000000000; // logic for get the min component
       for (int i=0; i<item.length; i++)
       {     

              if (item[i] < min)
                     min= item[i];
       }     
       System.out.println("The min component is: " + min);
       input.close(); // close to get the input
}
      
}


//Written in Java By Syed Ali Haider
//Student of The Hajvery University,Lahore, Pakistan.
//Don't remove these lines for legal use
//For more Please contact us.

Comments

Popular posts from this blog

Umbrella activities in Software Engineering

Operating System | Best Definition of Opetating System