首页 > 其他分享 >有6个评委打分,去掉一个最高分和最低分,求剩下4的评委的平均分

有6个评委打分,去掉一个最高分和最低分,求剩下4的评委的平均分

时间:2022-11-27 01:56:14浏览次数:55  
标签:arr int System 最高分 println 评委 out 平均分

package com.ShiXun_JiChu;

import java.util.Scanner;

public class day20221121_评委打分 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] arr = new int[6];
System.out.println("请输入第一个评委的打分:");
while (scanner.hasNextInt()) {
int a = scanner.nextInt();
System.out.println("请输入第二个评委的打分:");
int b = scanner.nextInt();
System.out.println("请输入第三个评委的打分:");
int c = scanner.nextInt();
System.out.println("请输入第四个评委的打分:");
int d = scanner.nextInt();
System.out.println("请输入第五个评委的打分:");
int e = scanner.nextInt();
System.out.println("请输入第六个评委的打分:");
int f = scanner.nextInt();
arr[0] = a;
arr[1] = b;
arr[2] = c;
arr[3] = d;
arr[4] = e;
arr[5] = f;
//最大值
int AA = qq(arr);
//最小值
ww(arr);
int BB = arr[0];
//该数组的数组元素总值
int CC=ff(arr);
System.out.println("该学生的成绩为:");
System.out.println((CC-AA-BB)/4);
}
System.out.println("输入不是数字或者整数!");
}
//输出数组中最大值的方法
public static int qq(int[] arr) {
int a = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] > a) {
a = arr[i];
}
}
return a;
}

//输出数组中最小值的方法 4 3 2 1 >>1 2 3 4
public static void ww(int[] arr) {
int a=0;// 0 1 2 3 2 1
for (int i = 0; i <arr.length-1 ; i++) {
for (int j = 0; j <arr.length-1-i ; j++) {
if (arr[j]>arr[j+1]){
a=arr[j];
arr[j]=arr[j+1];
arr[j+1]=a;
}
}
}
}
//遍历数组元素的方法
public static void ee(int []arr){
for (int i = 0; i <arr.length ; i++) {
System.out.println(arr[i]);
}
}
//将数组中的所有元素加起来
public static int ff(int []arr) {
int a = 0;
for (int i = 0; i < arr.length; i++) {
a = arr[i] + a;
}
return a;
}
}
/*
while循环那里可以使用更加简便的方式:可以利用for循环或者while循环
输出数组中最小的值也是能够更简便:详解见类名:输出数组中的最小值
*/

标签:arr,int,System,最高分,println,评委,out,平均分
From: https://www.cnblogs.com/CHX249/p/16928850.html

相关文章