package 专题练习;
import java.util.Scanner;
public class marking_by_judges {
//需求:在唱歌比赛中,有6名评委给选手打分,范围是[0,100]的整数.
//选手最后得分为去掉最高分和最低分的平均分
public static void main(String[] args) {
//储存分数数组
int[] score_six = new int[6];
for (int i = 0; i < 6; i++) {
System.out.println("please input NO." + " " + (i+1) + " " + "number :");
score_six[i] = score();
if(score_six[i] == -1) {
System.out.println("No. " + (i + 1) + " is wrong");
return;
}
}
avg_score(score_six);
}
//打分
public static int score(){
Scanner k = new Scanner(System.in);
int num = k.nextInt();
if(num > 100 || num < 0){
return -1;
}
return num;
}
//算均分
public static void avg_score(int[] data){
int temp;
//先从小到大排序 , 当然也可以直接找到最大值和最小值
for (int i = 0; i < data.length ; i++) {
for (int j = i+1; j < data.length ; j++) {
if(data[i] > data[j]){
temp = data[j];
data[j] = data[i];
data[i] = temp;
}
}
}
int sum = 0;
for (int t = 1; t < data.length - 1; t++) {
sum = sum + data[t];
}
System.out.println("The average number is " + sum * 1.0 / 4.0);
}
}
java专项练习(评分)
不会,就是不会!2023-09-20 19:59
相关推荐
鹿角片ljp6 小时前
LeetCode 64:最小路径和复盘|二维 DP 与 ACM 模式完整写法aramae6 小时前
模拟实现strcmp()(C语言)泡海椒7 小时前
PDF 表格样式优化:jquick-pdf 边框、圆角、背景色Beyond_System|系统之外8 小时前
【学编程】Python基础编程题100道(21-60)景熙55238 小时前
15.Java 8 Stream 流入门到实战wno7049 小时前
Spring Security权限控制杨运交9 小时前
[071][验证码模块]基于Spring拦截器的验证码认证设计思想Geek-Chow9 小时前
CountDownLatch in JavaSL_staff10 小时前
从RBAC到场景化授权:《无忧·企业文档》三级权限模型的技术实践解析