@Test
public void average() {
double ave = 0;
double sum = 0;
double min = 0;
double max = 0;
//往数组输入数值
Scanner InputPepole =new Scanner(System.in);
while (true) {
System.out.println("请输入有几位评委:");
int i=InputPepole.nextInt();
double scores[] = new double[i];
if(i<=2) {//要求最少三位评委
System.out.println("请输入两位以上评委人数!");
}else {
for(int j = 0;j < i; j++) {
System.out.println("请输入第"+(j+1)+"位评委的打分:");
scores[j]=InputPepole.nextDouble();
}
//从数组读出数值
for (int j = 0; j < scores.length; j++) {
min = scores[0];
max = scores[0];
sum = sum + scores[j];
if (scores[j] < min) {
min = scores[j];
}
if (scores[j] > max) {
max = scores[j];
}
}
ave = (sum - max - min)/(i-2);
System.out.println("平均分数为:"+ave);
}
break;
}
InputPepole.close();
}
输入n位评委,并输入评委的打分,去掉最高最低分求均值
最新推荐文章于 2023-06-03 14:01:47 发布