package practice;
import java.util.Arrays;
import java.util.Scanner;
public class GameScore {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int score[] = new int[10];
for (int i = 0; i < score.length; i++) {
System.out.print("请" + (i + 1) + "号评委出示分数:");
score[i] = sc.nextInt();
}
Arrays.sort(score); // 数组元素升序排序
int sumScore = 0; // 总分
int sumTimes = 0; // 剔除最高分及最低分后的剩余场次
for (int i = 0; i < score.length; i++) {
if (score[i] == score[0] || score[i] == score[score.length - 1]) {
continue;
} else {
sumScore += score[i];
sumTimes++;
}
}
System.out.print("\n最高分: " + score[score.length - 1] + ",最低分:" + score[0]);
System.out.println(",场次:" + sumTimes + ",总分:" + sumScore);
System.out.println();
System.out.println("提示:剔除最高分和最低分后,选手最后的平均得分是" + (sumScore / sumTimes) + "分!");
sc.close();
}
}
Java剔除最高分最低分后求平均分
最新推荐文章于 2024-02-08 23:01:39 发布