小蓝给学生们组织了一场考试,卷面总分为 分,每个学生的得分都是一个 到 的整数。 请计算这次考试的最高分、最低分和平均分。

n=int(input())
max,min,av=0,9999,0
for i in range(n):
    a=
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 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、付费专栏及课程。

余额充值