Java七个评委打分,要求输入七个评委的打分分数,取代偶一个最高分和一个最低分后,求出该参赛者的总得分
时间: 2024-05-20 18:19:36 浏览: 7
以下是Java代码实现:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] scores = new int[7]; // 存储七个评委的打分
int sum = 0; // 总得分
int max = Integer.MIN_VALUE; // 最高分,初始值为最小值
int min = Integer.MAX_VALUE; // 最低分,初始值为最大值
// 输入七个评委的打分
for (int i = 0; i < 7; i++) {
System.out.print("请输入第" + (i + 1) + "个评委的打分:");
scores[i] = scanner.nextInt();
// 更新最高分和最低分
if (scores[i] > max) {
max = scores[i];
}
if (scores[i] < min) {
min = scores[i];
}
}
// 计算总得分
for (int score : scores) {
if (score != max && score != min) { // 排除最高分和最低分
sum += score;
}
}
// 输出总得分
System.out.println("该参赛者的总得分为:" + sum);
}
}
```
运行截图:
![Java七个评委打分](https://cdn.luogu.com.cn/upload/image_hosting/gkx6es9j.png)