Highest and lowest scores

Input
two lines, the first line is an integer n (1<=n<10000), which indicates the number of people who participated in the test; the second line is the scores of the n students, and the adjacent scores are separated by spaces. Scores are integers between 0 and 100.
Output
Output the highest and lowest scores, separated by spaces.
Sample input
5
60 70 50 80 95

Sample output
95 50

import java.util.Scanner;
class Main {

    public static void main(String[] args) {
        int min=100,max=0;
        Scanner scan=new Scanner(System.in);
        int a=scan.nextInt();
        int[] b=new int [a];
        for(int i=0;i<a;i++)
        {
            b[i]=scan.nextInt();
            if(b[i]>max)
                max=b[i];
            if(b[i]<min)
                min=b[i];
        }
        System.out.print(max+" ");
        System.out.println(min);
    }

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325190871&siteId=291194637