package com.zhao.test;

import java.util.Scanner;

public class Test17 {
/* 需求 :
在唱歌比赛中,有6名评委给选手打分,分数范围是[0 - 100]之间的整数。
选手的最后得分为:去掉最高分、最低分后的4个评委的平均分,
请完成上述过程并计算出选手的得分。*/
public static void main(String[] args) {
int[] scoresArr=getScores();
int max=getMax(scoresArr);
int min=getMin(scoresArr);
int sum=getSum(scoresArr);
//4.求平均分(和-最大值-最小值)/4
//不直接写4,不写死
int avg=(sum-max-min)/(scoresArr.length-2);
System.out.println("选手的平均得分为: "+avg);
} //分析 1.定义一个方法用来建立数组用于存储分数
public static int[] getScores(){
int[] scores=new int[6];
//录入分数
Scanner sc=new Scanner(System.in);
for (int i = 0; i <scores.length ; ) {
System.out.println("请输入分数:");
int score=sc.nextInt();
if (score>=0&&score<=100){
scores[i]=score;
i++;
}else {
System.out.println("录入分数不合法,请重新输入:");
}
}
return scores;
} //2.求出数组中的最大值
public static int getMax(int[] scores){
int max=scores[0];
for (int i = 0; i <scores.length ; i++) {
if (max<scores[i]){
max=scores[i];
}
}
return max;
} //3.求出数组中的最小值
//shift+F6批量修改方法内同名元素
public static int getMin(int[] scores){
int min=scores[0];
for (int i = 0; i <scores.length ; i++) {
if (min>scores[i]){
min=scores[i];
}
}
return min;
}
//3.求出数组中的6个分数的和
public static int getSum(int[] scores){
int sum=0;
for (int i = 0; i <scores.length ; i++) {
sum=sum+scores[i];
}
return sum;
} }

最新文章

  1. Bestcoder Round 47 &amp;&amp; 48
  2. web进阶之jQuery操作DOM元素&amp;&amp;MySQL记录操作&amp;&amp;PHP面向对象学习笔记
  3. java.lang.reflect.Field
  4. paper 112:hellinger distance
  5. Yii路径总结
  6. 在CentOS上装 ElasticSearch
  7. B/S C/S架构的界面测试
  8. 【Qt】Qt之Tab键切换焦点顺序【转】
  9. Linux进程关系(转载)
  10. 说说Android的MVP模式
  11. python --github 刷题
  12. js 图片与base64互相转换
  13. 1 CRM
  14. &lt;时间的玫瑰&gt;读书笔记
  15. [CodeForces_618C]Constellation
  16. Javascript 对象继承 原型链继承 对象冒充 call 混合方式
  17. Android Studio 换主题(Material Theme..)
  18. 前端路由的两种模式: hash 模式和 history 模式
  19. 第二篇:shell基础命令(部分)
  20. 将int型数值拆分成4字节

热门文章

  1. 【Linux】常用
  2. tensorrt cuda cudnn 各版本的匹配要求
  3. python安装及简单爬虫(爬取导师信息)
  4. C# 将Dll文件打包到exe中
  5. 无线网络技术 实验2 无线网络环境RSSI测试实验
  6. flutter SliverPersistentHeader子组件透明度渐变【滑动悬停appbar添加自定义组件的透明度】
  7. 2023-03-01 &#39;react-native&#39; 不是内部或外部命令,也不是可运行的程序 这个报错是因为你没有全局安装react-native的脚手架,请执行下面代码全局安装react-native脚手架&#128071;
  8. PyTorch Geometric(pyg)学习
  9. Java获取当前服务器域名、IP、端口
  10. windows系统修复