java7个评委给5位选手打分每位选手去掉评委的最高分和最低分 最后得出选手的最后的平均值,并且打印出小票,获得全部选手 的得分信息标注前三名选手
时间: 2024-06-05 21:06:35 浏览: 14
import java.util.Arrays;
public class ScoreCalculator {
public static void main(String[] args) {
int[][] scores = {{9, 8, 7, 6, 5, 4, 3}, {5, 7, 8, 9, 6, 4, 2}, {6, 5, 4, 7, 8, 9, 3}, {8, 7, 6, 5, 4, 3, 2}, {7, 6, 8, 9, 5, 4, 3}};
String[] players = {"A", "B", "C", "D", "E"};
double[] averages = new double[5];
for (int i = 0; i < scores.length; i++) {
int[] sortedScores = Arrays.copyOf(scores[i], scores[i].length);
Arrays.sort(sortedScores);
int sum = 0;
for (int j = 1; j < sortedScores.length - 1; j++) {
sum += sortedScores[j];
}
averages[i] = (double) sum / (sortedScores.length - 2);
}
// 打印小票
System.out.println("选手\t得分信息");
for (int i = 0; i < players.length; i++) {
System.out.print(players[i] + "\t");
for (int j = 0; j < scores[i].length; j++) {
System.out.print(scores[i][j] + " ");
}
System.out.println("去掉最高分和最低分后的平均分:" + averages[i]);
}
// 标注前三名选手
int[] sortedIndexes = new int[5];
for (int i = 0; i < sortedIndexes.length; i++) {
sortedIndexes[i] = i;
}
for (int i = 0; i < sortedIndexes.length - 1; i++) {
for (int j = i + 1; j < sortedIndexes.length; j++) {
if (averages[i] < averages[j]) {
int temp = sortedIndexes[i];
sortedIndexes[i] = sortedIndexes[j];
sortedIndexes[j] = temp;
}
}
}
System.out.println("前三名选手:");
for (int i = 0; i < 3; i++) {
System.out.println((i + 1) + ". " + players[sortedIndexes[i]] + ",平均分:" + averages[sortedIndexes[i]]);
}
}
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)