解题思路:使用list来存放个等级的成绩,通过collections的sort方法和reverse方法进行降序
注意事项:
参考代码:
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); //获取n个数据 int arr[] = new int[n]; //构造成绩数组 for (int i = 0; i < n; i++) { arr[i] = scanner.nextInt(); } ArrayList<Integer> gradeA = new ArrayList<>(); ArrayList<Integer> gradeB = new ArrayList<>(); ArrayList<Integer> gradeC = new ArrayList<>(); ArrayList<Integer> gradeD = new ArrayList<>(); ArrayList<Integer> gradeE = new ArrayList<>(); List[] o ={gradeA,gradeB,gradeC,gradeD,gradeE}; int countA = 0; int countB = 0; int countC = 0; int countD = 0; int countE = 0; for (int i : arr) { if (i >= 90) { countA++; gradeA.add(i); } else if (i >= 80) { countB++; gradeB.add(i); } else if (i >= 70) { countC++; gradeC.add(i); } else if (i >= 60) { countD++; gradeD.add(i); } else { countE++; gradeE.add(i); } } int[] grade = {countA, countB, countC, countD, countE}; int max = 0; for (int j = 0; j < grade.length; j++) { if (max < grade[j]) { max = grade[j]; } } for (int i : grade) { System.out.print(i+" "); } System.out.println(); System.out.println(max); for (List o1 : o) { if (o1.size()==max){ Collections.sort(o1); Collections.reverse(o1); for (Object o2 : o1) { System.out.print(o2+" "); } } } }
0.0分
1 人评分
2004年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:681 |
矩形面积交 (C语言代码)浏览:1511 |
震宇大神的杀毒软件 (C语言代码)浏览:1240 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:619 |
哥德巴赫曾猜测 (C语言代码)浏览:994 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:500 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:879 |
三角形 (C语言代码)浏览:903 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:531 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:561 |