蓝桥杯刷题 | 小蓝给学生们组织了一场考试,卷面总分为 100 分,每个学生的得分都是一个 0 到 100 的整数。

题目描述

小蓝给学生们组织了一场考试,卷面总分为 100 分,每个学生的得分都是一个 0 到 100 的整数。

如果得分至少是 60 分,则称为及格。如果得分至少为 85 分,则称为优秀。

请计算及格率和优秀率,用百分数表示,百分号前的部分四舍五入保留整 数。

输入描述

输入的第一行包含一个整数 n\ (1 \leq n \leq 10^4)n (1≤n≤104),表示考试人数。

接下来 nn 行,每行包含一个 0 至 100 的整数,表示一个学生的得分。

输出描述

输出两行,每行一个百分数,分别表示及格率和优秀率。百分号前的部分 四舍五入保留整数。

输入输出样例

输入

7
80
92
56
74
88
100
0

输入

71%
43%

运行限制

  • 最大运行时间:1s
  • 最大运行内存: 256M

实现代码

import java.util.Scanner;

public class chengji {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
          arr[i] = scan.nextInt();
        }
        math(arr);
        scan.close();
    }

    public static void math(int[] arr){
    	int jige = 0;  //及格人数
    	int youxiu = 0;   //优秀人数
        for(int i=0;i<arr.length;i++){
          if(arr[i] >= 85) {
        	  youxiu++;
          }
          if(arr[i] >= 60) {
        	  jige++;
          }
        }
        //为得到正确集合率和优秀率,先按浮点数计算,再转为整数(这里浮点数没办法直接转换成整数,所有曲折了一点)
        Float jigeLv = (float)jige / arr.length * 100;
        Float youxiuLv = (float)youxiu / arr.length * 100;
        Integer j = (int)((float)jige / arr.length * 100);
        Integer x = (int)((float)youxiu / arr.length * 100);
        //四舍五入
        if(jigeLv * 10 % 10 >=5 ) {
        	j += 1;
        }
        if(youxiuLv * 10 % 10 >=5 ) {
        	x += 1;
        }
        
        System.out.println(j + "%");
        System.out.println(x + "%");
    }
  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 最高 = 100 最低 = 0 平均 = 所有学生得分之和 / 学生人数 以下是使用JAVA代码实现计算最高、最低和平均的方法: ```java public class Exam { public static void main(String[] args) { int[] scores = { 85, 92, 76, 99, 64, 80, 90, 88, 70, 78 }; int sum = 0; int max = scores[0]; int min = scores[0]; for (int i = 0; i < scores.length; i++) { sum += scores[i]; if (scores[i] > max) { max = scores[i]; } if (scores[i] < min) { min = scores[i]; } } double avg = (double) sum / scores.length; System.out.println("最高:" + max); System.out.println("最低:" + min); System.out.println("平均:" + avg); } } ``` 假设这场考试有10名学生,他们的得分别是85、92、76、99、64、80、90、88、70和78。代码中定义了一个整型数组来存储学生得分,然后使用for循环遍历数组,计算、最高和最低。最后,通过将除以学生人数,得到平均,并将三个结果输出到控制台。 ### 回答2: import java.util.Scanner; public class ExamScores { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numStudents; int maxScore = 0; int minScore = 100; int totalScore = 0; System.out.print("请输入学生人数:"); numStudents = sc.nextInt(); for (int i = 1; i <= numStudents; i++) { System.out.print("请输入第" + i + "个学生数:"); int score = sc.nextInt(); if (score > maxScore) { maxScore = score; } if (score < minScore) { minScore = score; } totalScore += score; } double averageScore = (double) totalScore / numStudents; System.out.println("最高:" + maxScore); System.out.println("最低:" + minScore); System.out.println("平均:" + averageScore); sc.close(); } } ### 回答3: 可以使用Java代码来计算这次考试的最高、最低和平均。 首先,需要声明一个包含学生得分整数数组,然后根据数组元素来计算最高、最低和平均。 ```java public class ExamScore { public static void main(String[] args) { int[] scores = {85, 92, 78, 96, 88}; // 假设有5个学生得分 int maxScore = scores[0]; // 假设第一个学生得分为最高 int minScore = scores[0]; // 假设第一个学生得分为最低 int sum = scores[0]; // 假设第一个学生得分 for (int i = 1; i < scores.length; i++) { if (scores[i] > maxScore) { maxScore = scores[i]; // 更新最高 } if (scores[i] < minScore) { minScore = scores[i]; // 更新最低 } sum += scores[i]; // 计算 } double averageScore = (double) sum / scores.length; // 计算平均 System.out.println("最高:" + maxScore); System.out.println("最低:" + minScore); System.out.println("平均:" + averageScore); } } ``` 以上代码中,我们使用一个for循环来遍历学生得分数组,逐个比较得分并更新最高和最低。同时,计算的变量sum也会逐步增加每个学生得分。最后,通过除以学生数量来计算平均。 运行代码后,将输出最高、最低和平均的结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

少糖加水

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值