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
相关推荐
mengge.cloud2 小时前
Python基础保姆级!从入门到入土Resean02232 小时前
Spring 源码分析(六)循环依赖与三级缓存在爪洼山玩泥巴2 小时前
fastjson2 JSONPath 取不存在路径,为什么会抛 “not support”?星落梦生12 小时前
SpringAOP基础笔记(7)金銀銅鐵13 小时前
带您看懂字节码指令(四):一条指令里有什么最强小杰13 小时前
某 OpenAI 兼容网关上的 `kimi-k3.1-pro`:Cline、Zed 接入与 SSE 排错示例Flynn Liang14 小时前
流量治理不是限流那么简单:I/O 密集型 Java 服务的 6 层防线学长毕设14 小时前
基于SpringBoot智慧养老服务平台设计与实现-附源码曹牧14 小时前
Java:“刷新雪崩”郝学胜-神的一滴14 小时前
Effective STL 条款03:容器中的对象复制要廉价且正确