评委打分,去掉最高分,最低分,求平均分



import java.util.Scanner;

public class Test5 {
    public static void main(String[] args) {
        //评委打分,去掉最高分,最低分,求平均分

        int[] scoreArr = getScores();
        
        int max = getMax(scoreArr);
        int min = getMin(scoreArr);
        int sum = getSum(scoreArr);

        int result = sum-max-min;
        System.out.println("评分中最大值是"+max);
        System.out.println("评分中最小值是"+min);
        System.out.println("最值评分结果是"+result);


    }

    //数组元素求和
    public static int getSum(int[] scoreArr) {
        int sum = 0;
        for (int i = 0; i < scoreArr.length; i++) {
            sum = sum + scoreArr[i];
        }
        return sum;

    }

    //找出数组中的最小值
    private static int getMin(int[] scoreArr) {
        int min = scoreArr[0];
        for (int i = 0; i < scoreArr.length; i++) {
            if (scoreArr[i] < min) {
                min = scoreArr[i];
            }
        }
        return min;
    }

    //找出数组中的最大值
    private static int getMax(int[] scoreArr) {
        int max = scoreArr[0];
        for (int i = 0; i < scoreArr.length; i++) {
            if (scoreArr[i] > max) {
                max = scoreArr[i];
            }
        }
        return max;
    }

    private static int[] getScores() {
        int[] scores = new int[6];
        Scanner sc = new Scanner(System.in);

        for (int i = 0; i < scores.length; ) {
            System.out.println("请输入" + (i + 1) + "号评委的打分");
            int score = sc.nextInt();
            if (score >= 0 && score <= 100) {
                scores[i] = score;
                i++;
            } else {
                System.out.println("你输入的分数有误,请重新输入");

            }
        }
        return scores;


    }


}

你可能感兴趣的:(数据结构,java,算法,开发语言)