分析成绩 Exercise07_04
1 import java.util.Scanner; 2 /** 3 * @author 冰樱梦 4 * 时间:2018年下半年 5 * 题目:分析成绩 6 * 7 */ 8 public class Exercise07_04 { 9 public static void main(String[] args){ 10 int higher=0,equal=0,lower=0,sum=0; 11 double average,total=0,num; 12 double[] grade=new double[101]; 13 Scanner input=new Scanner(System.in); 14 System.out.println("输入考试分数,以负数结束"); 15 while(true){ 16 num=input.nextInt(); 17 if(num<0) break; 18 sum++; 19 grade[(int) num]=num; 20 } 21 for(int i=0;i<grade.length;i++){ 22 total+=grade[i]; 23 } 24 average=total/sum; 25 for(int i=0;i<101;i++){ 26 if((grade[i]!=0) && (grade[i]<average)) lower++; 27 if(grade[i]==average) equal++; 28 if(grade[i]>average) higher++; 29 } 30 System.out.println("There are "+ higher+" higher than average grade,"+lower+" lower than average grade,and "+equal+" equal average grade"); 31 } 32 }