java编写一个程序,读入数目确定的考试分数,并且判断有多少个分数高于或等于平均分,有多少个分数低于平均分。输入一个负数标志输入结束,假设最高分为100。
时间: 2023-05-17 11:05:55 浏览: 150
以下是 Java 代码实现:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int sum = 0;
int count = 0;
int score;
int average;
while (true) {
score = scanner.nextInt();
if (score < 0) {
break;
}
sum += score;
count++;
}
average = sum / count;
int above = 0;
int below = 0;
scanner = new Scanner(System.in);
while (true) {
score = scanner.nextInt();
if (score < 0) {
break;
}
if (score >= average) {
above++;
} else {
below++;
}
}
System.out.println("平均分:" + average);
System.out.println("高于或等于平均分的人数:" + above);
System.out.println("低于平均分的人数:" + below);
}
}
希望能够帮到你!
阅读全文