1,选秀比赛,8个评委,十分制,可以有小数点
输入8个评委的分数,去掉一个最高分,去掉一个最低分,剩下的求平均值
import java.util.Scanner;
public class Demo08 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//定义一个数组
double[] scores = new double[8];
//依次输入8个评分
for (int i = 0; i < scores.length; i++) {
System.out.println("请你输入第"+(i+1)+"个评委的分数");
scores[i] = sc.nextDouble();
}
double max = scores[0];
double min = scores[0];
for (int i = 1; i < scores.length; i++) {
if (max < scores[i]) {
max = scores[i];
}
if (min > scores[i]){
min = scores[i];
}
}
double sum = 0;
for (int i = 0; i < scores.length; i++) {
sum += scores[i];
}
//去掉一个最大最小值
sum = sum - max - min;
//求平均值
double avg = sum/(scores.length - 2);
System.out.println("减去一个最高分和一个最低分,最后平均分为:"+ avg);
}
}