运行效果如下
2条回答 默认 最新
关注
示例代码如下:
public class Test { public static void main(String[] args) { List<List<Double>> students = new ArrayList<>(); Scanner scanner = new Scanner(System.in); for (int i = 0; i < 3; i++) { List<Double> scores = new ArrayList<>(); students.add(scores); for (int j = 0; j < 4; j++) { System.out.printf("请输入第%s位学生的第%s门课程的成绩:", (i + 1), (j + 1)); scores.add(scanner.nextDouble()); } } for (int i = 0; i < students.size(); i++) { System.out.printf("第%s位学生的课程成绩:", i + 1); double total = 0; for (int j = 0; j < students.get(i).size(); j++) { Double score = students.get(i).get(j); total += score; System.out.print(score + "\t"); } double avg = total / students.get(i).size(); System.out.print("总成绩:" + total + "\t"); System.out.print("平均值为:" + avg + "\t\n"); } } }
运行效果如下:
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用