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
相关推荐
2601_949146536 小时前
C语言语音通知接口接入教程:如何使用C语言直接调用语音预警API曹牧6 小时前
Spring Boot:如何测试Java Controller中的POST请求?KYGALYX7 小时前
服务异步通信zmzb01037 小时前
C++课后习题训练记录Day98爬山算法7 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?kfyty7257 小时前
集成 spring-ai 2.x 实践中遇到的一些问题及解决方案猫头虎7 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题李少兄7 小时前
在 IntelliJ IDEA 中修改 Git 远程仓库地址YUJIANYUE8 小时前
PHP纹路验证码忆~遂愿8 小时前
ops-cv 算子库深度解析:面向视觉任务的硬件优化与数据布局(NCHW/NHWC)策略