SumanSharmaTech / Not-a-Excluded-Project

you can add any codes in any language by creating its respective folder (if already not available).
8 stars 32 forks source link

Max and min element of an array #52

Open somya121 opened 2 years ago

somya121 commented 2 years ago

import java.util.Scanner; public class max_min { public static void main(String args[]){ Scanner in = new Scanner(System.in);

    System.out.println("Enter the length of array - ");
    int n = in.nextInt();
    System.out.println("Enter numbers in array - ");
    int array[] = new int[n];
    for(int i=0;i<n;i++){
        array[i] = in.nextInt();
    }
    int max =array[0];
    int min= array[0];
    for(int i=0;i<n;i++){
        if(array[i]<min)
        { min = array[i];
        }
        if(array[i]>max){
            max = array[i];
        }
    }
    System.out.println("Minimum - "+min);
    System.out.println("Maximum - "+max);        
}

}