题解 | #数组遍历#
数组遍历
https://www.nowcoder.com/practice/0f8219cb6f6e4e99a1bb0e868e51d60a
import java.util.Scanner; public class Main { public static void main(String[] args) { int[] ary = new int[6]; int max; int min; Scanner scanner = new Scanner(System.in); for (int i = 0; i < ary.length ; i++) { ary[i] = scanner.nextInt(); } for (int i = 0; i < ary.length; i++) { for (int j = 0; j < ary.length - 1; j++) { if (ary[j] > ary[j + 1]) { int temp = ary[j]; ary[j] = ary[j + 1]; ary[j + 1] = temp; } } } min = ary[0]; int b = ary.length; max = ary[b - 1]; //write your code here...... System.out.println(max + " " + min); } }
用冒泡排序使数组进行排序,数组最后是最大的,第一个是最小的