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
相关推荐
努力努力再努力wz1 分钟前
【Lua 入门系列】模块与包(一):从多文件组织到require 运行时加载机制、模块缓存、预加载搜索与 Lua 文件搜索机制Jack_hsfs3 分钟前
第6章Spring 管理的是对象,还是对象的说明书?fengci.6 分钟前
CTF2困难部分佳得动7 分钟前
编译和链接的认识(C语言)大黄说说17 分钟前
PHP 异步怎么实现?Swoole、Workerman 使用场景对比十二同学啊18 分钟前
Python 工程化详解:项目结构、依赖管理、代码质量、测试与部署YIN_尹22 分钟前
【git原理与使用】git基本操作及底层原理(一)乐橙开放平台24 分钟前
跨地域监控难管理?通过 GB28181 把各地海康大华乐橙摄像头注册到云端平台广东融科数据服务有限公司26 分钟前
网络监控经常卡顿、掉线、画面模糊?一线排查问答实录程序员飞哥32 分钟前
AI 编程额度怎么用才不浪费?