publicclassDemo { publicstaticvoidmain(String[] args) { Scannerinput=newScanner(System.in); finalintN=10; float[] array = newfloat[N]; float Max, Min, Average = 0; System.out.println("please enter the " + N + " students test results in order:"); for (inti=0; i < N; i++) { array[i] = input.nextFloat(); } Max = Min = array[0]; for (inti=0; i < N; i++) { if (array[i] > Max) Max = array[i]; if (array[i] < Min) Min = array[i]; Average += array[i]; } Average /= N; System.out.format("highest score:%.1f,lowest score:%.1f,the average score:%.2f",Max,Min,Average); } }
intmain() { floatarray[N], Max,Min,Average; printf("please enter the N students test results in order:"); for (int i = 0; i < N; i++) { scanf("%f", &array[i]); } Max =Min=array[0]; for (int i = 0; i < N; i++) { if (array[i] > Max) Max = array[i]; elseif (array[i] < Min) Min = array[i]; Average += array[i]; } Average /= N; printf("highest score:%.1f,lowest score:%.1f,the average score:%.3f", Max, Min, Average); return0; }