需求:对评委的分数进行录入,同时去掉最低分、最高分来计算选手的最终成绩
代码实现:
import java.util.Scanner;
public class Test5 {
public static void main(String[] args) {
//黑马案例03-评委打分
int [] FirstScore =new int[6];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < FirstScore.length; i++) {
System.out.println("请输入第"+(i+1)+"个评委的打分分数,整数打分");
FirstScore[i] = sc.nextInt();
}
System.out.println("该选手的最终成绩为" + score(FirstScore, FirstScore.length));
}
public static double score(int [] score, int number) {
double sum =0;
double max = score[0];
double min = score[0];
for (int i = 0; i < score.length; i++) {
sum+=score[i];
if (max < score[i])
{
max = score[i];
}
else if (min > score[i])
{
min = score[i];
}
}
double average = (sum - max - min)/(score.length-2);
return average;
}
}