JAVA输出最大值和最小值

public class MaxMin{
    public static void main(String[] args) {
        int[] arr = new int[6];
        Scanner input = new Scanner(System.in);
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个数字:");
            int number = input.nextInt();
            arr[i] = number;
        }
        int sum = 0, min = arr[0], max = min;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
            if (min > arr[i]) {
                min = arr[i];
            }
            if (max < arr[i]) {
                max = arr[i];
            }
        }
        System.out.println("最大值:" + max);
        System.out.println("最小值:" + min);
    }
}

 

posted @ 2017-10-23 18:53  ichimoku  阅读(17601)  评论(0编辑  收藏  举报