public class HelloWorld { publicstatic void main(String[] args) { System.out.println("HelloWorld"); } } public static void main(String[] args) { //创建数组 int[] arr=new int[6]; //键盘录入 Scanner sc = new Scanner(System.in); //遍历数组循环 for(int i=0;i<arr.length;i++){ System.out.println("第"+(i+1)+"分数"); int a=sc.nextInt(); //赋值变量 arr=a; } //遍历数组得出最大值和最小值 int max = arr[0];//赋值数组中的任意一个数 int min = arr[0]; int sum = 0; for (int i = 0; i < arr.length; i++) { sum+=arr;//sum = sum+arr if (max<arr) { max = arr; } if (min>arr) { min = arr; } } System.out.println(max); System.out.println(min); System.out.println(Arrays.toString(arr));//打印数组 int avg = (sum-max-min)/4; System.out.println(avg);
|