package Demo;
import java.util.Scanner;
public class Test5 {
public static void main(String[] args) {
//目标:计算6个评委的平均分(去掉最高和最低分)
//1.创建数组接收并录入6个评委的分数
Scanner sc = new Scanner(System.in);
double[] scores = new double[6];
for (int i = 0; i < scores.length; i++) {
System.out.println("请您输入第" + (i+1) + "位评委的打分:");
scores[i] = sc.nextDouble();
}
//2.统计最高分,最低分以及总分
double max = scores[0], min = scores[0], sum = 0;
for (int i = 0; i < scores.length; i++) {
if (scores[i] > max) {
//替换最高分
max = scores[i];
}
if (scores[i] < min){
//替换最低分
min = scores[i];
}
//统计最高分
sum += scores[i];
}
//3.计算最终得分
float result = (float) ((sum - max -min) * 1.0/ (scores.length - 2));
System.out.println("该位选手的最终得分为:" + result);
}
}
【Java练习】计算评委打分
最新推荐文章于 2023-02-19 19:20:43 发布