浅蓝


私信TA

用户名:qianlan

访问量:266

签 名:

等  级
排  名 36563
经  验 374
参赛次数 0
文章发表 1
年  龄 0
在职情况 学生
学  校 南通大学
专  业

  自我简介:

解题思路:使用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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区