输入n个学生的姓名及其3门功课成绩,要求按输入的逆序逐行输出每个学生的姓名、3门课成绩和平均成绩。若有学生平均成绩低于60分,则不输出该学生信息。平均成绩保留小数点后两位。使用Java语言
时间: 2023-12-17 13:04:58 浏览: 88
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
String[] names = new String[n];
double[][] scores = new double[n][3];
double[] averages = new double[n];
for (int i = 0; i < n; i++) {
names[i] = scanner.next();
for (int j = 0; j < 3; j++) {
scores[i][j] = scanner.nextDouble();
}
averages[i] = (scores[i][0] + scores[i][1] + scores[i][2]) / 3;
}
for (int i = n - 1; i >= 0; i--) {
if (averages[i] >= 60) {
System.out.printf("%s %.2f %.2f %.2f %.2f\n", names[i], scores[i][0], scores[i][1], scores[i][2], averages[i]);
}
}
}
}
阅读全文