问题:从键盘中接收十个数,输出其最大值,最小值;
代码:
public static void main(String[] args) { /* 1.接受十个数 2.将十个数收入数组,判断最大值,最小值 3。输出 */ Scanner scanner = new Scanner(System.in); int a[] = new int[10]; for (int i = 0; i < a.length; i++) { a[i] = scanner.nextInt(); } System.out.println(Arrays.toString(a)); int max = a[0]; int min = a[a.length-1]; for (int i = 1; i < a.length; i++) { if (max < a[i]) { max = a[i]; } } for (int i = a.length-2; i >-1 ; i--) { if(min>a[i]){ min = a[i]; } } System.out.println(max); System.out.println(min); }