<> 第十一届蓝桥杯省赛 Java 大学 B 组—成绩分析—满分百分题解

<>一、解题思路

<>1、解法一( Java )

解法思路:简单模拟
☝循环遍历求和 sum 并更新最大值 max 和最小值 min,最后格式化保留两位小数输出平均值 String.format("%.2f", res)

伪代码如下:
/** * @author Listen 1024 * @description 第十一届蓝桥杯省赛 Java 大学 B 组—成绩分析—满分百分题解 *
@date 2022-4-3 19:27:52 */ import java.util.Scanner; public class Main { public
static void main(String[] args) { Scanner scanner = new Scanner(System.in); int
n= scanner.nextInt(); int sum = 0, max = 0, min = 100; for (int i = 0; i < n; i
++) { int temp = scanner.nextInt(); if (temp > max) { max = temp; } if (temp <
min) { min = temp; } sum += temp; } double res = (double) sum / n; System.out.
println(max); System.out.println(min); System.out.println(String.format("%.2f",
res)); } }
运行结果截图如下:

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信