求参赛选手的平均成绩
发布日期:2021-06-30 11:20:14 浏览次数:2 分类:技术文章

本文共 795 字,大约阅读时间需要 2 分钟。

背景描述

选手参加比赛,有10个评委为参赛选手打分,分数为1到100。

选手最终得分的计算方式为:先去掉一个最高分和一个最低分;再将其余8个分数取平均值。

代码实现

package com.cn;import java.util.Scanner;/** * 本文作者:谷哥的小弟  * 博客地址:http://blog.csdn.net/lfdfhl  */public class AvgScore {	public static void main(String[] args) {		Scanner scanner = new Scanner(System.in);		int max = 0;		int min = 0;		int sum = 0;		double avg = 0;		for (int i = 1; i <= 10; i++){			System.out.print("请第" + i + "评委输入分数: ");			int score = scanner.nextInt(); 			sum = sum + score; 			if(i==1) {				max = score;				min = score;			}else {				if (score > max) {					max = score;				} 				if (score < min) {					min = score;				} 			}		}		System.out.println("去掉一个最高分:"+max);		System.out.println("去掉一个最低分:"+min);		avg = (sum - max - min) / 8;		System.out.println("选手最终的得分:"+avg);		scanner.close();	}}

运行效果

 

 

 

转载地址:https://it9527.blog.csdn.net/article/details/8195207 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Maven阿里巴巴镜像仓库配置
下一篇:Android常用控件之ImageView

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月07日 08时26分05秒