| 
 
| 复制代码package com.itheima;
import java.util.Arrays;
import java.util.Scanner;
/**
 * 第5题:编写程序接收键盘输入的5个数,装入一个数组,并找出其最大数和最小数。
 * 
 * @author Administrator
 * 
 */
public class Test5 {
        public static void main(String[] args) {
                findMaxOrMin();
        }
        // 查找最大和最小值
        public static void findMaxOrMin() {
                Scanner s = new Scanner(System.in);
                int[] a = new int[5];
                // 获取输入,存储到数组
                while (s.hasNextInt()) {
                        for (int i = 0; i < a.length; i++) {
                                a[i] = s.nextInt();
                        }
                        // 排序
                        Arrays.sort(a);
                        System.out.println("5个数中的最大值为:" + a[0]);
                        System.out.println("5个数中的最小值为:" + a[4]);
                }
                // 关闭资源
                s.close();
        }
}
怎么优化,一直在阻塞。。。等待输入。[/color]
 | 
 |