2024-05-17 14:55:52
2024-05-17 09:55:54
平均分,保留两位小数
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int studentCount = 10;
int totalScore = 0;
for (int i = 1; i <= studentCount; i++) {
System.out.println("请输入第" + i + "个学生的成绩:");
int score = scanner.nextInt();
totalScore += score;
}
System.out.println("平均分 ≈ " + new DecimalFormat("0.00").format((float)totalScore / studentCount));
}
}