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
相关推荐
小bo波12 小时前
使用Thread子类创建线程 VS 使用Runnable接口创建线程的区别SamDeepThinking13 小时前
高并发场景下,CompletableFuture与ForkJoinPool该如何取舍?张不才16 小时前
CPU 100% 了怎么办?Java 性能排障的标准化操作shepherd11117 小时前
吞吐量提升 10 倍:高并发大批量数据处理任务的架构演进与性能调优plainGeekDev20 小时前
单例模式 → object 声明用户2986985301421 小时前
Java 实现 Word 文档文本与图片提取的方法SimonKing1 天前
铁子,IntelliJ IDEA 2026.1.3来了,升不升?咖啡八杯1 天前
GoF设计模式——策略模式用户128526116022 天前
我把祖传Java项目重构后,接口响应从3s砍到了200ms,只改了这几行代码