
有没有人帮我修改一下代码?以下是我的代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 1. 读取学生人数
int n = sc.nextInt();
double[] scores = new double[n];
// 2. 读取n个成绩
for (int i = 0; i < n; i++) {
scores[i] = sc.nextDouble();
}
// 3. 初始化最大值、最小值和总分
double max = scores[0];
double min = scores[0];
double sum = 0.0;
// 4. 遍历计算最大值、最小值和总分
for (double s : scores) {
if (s > max) {
max = s;
}
if (s < min) {
min = s;
}
sum += s;
}
// 5. 计算平均分
double avg = sum / n;
// 6. 按格式输出(保留2位小数,顺序:最高分 最低分 平均分)
System.out.printf("%.2f %.2f %.2f\n", max, min, avg);
sc.close();
// 关键修复:显式指定程序正常退出,返回状态码 0
System.exit(0);
}
}