java:编写一个程序,统计某个班三门课语文、数学、英语的成绩:首先输入学生人数,然后依次输入各个学生的成绩,最后统计每个学生的课程平均成绩,及每门课的平均成绩,并列表输出。
时间: 2024-05-22 08:12:25 浏览: 211
用java语言编写统计学生成绩的程序
5星 · 资源好评率100%
import java.util.Scanner;
public class ScoreStatistics {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入学生人数:");
int stuNum = input.nextInt();
int[][] scores = new int[stuNum][3];
for (int i = 0; i < stuNum; i++) {
System.out.printf("请输入第%d个学生的语文、数学、英语成绩:\n", i + 1);
scores[i][0] = input.nextInt();
scores[i][1] = input.nextInt();
scores[i][2] = input.nextInt();
}
int sumCh = 0, sumMath = 0, sumEng = 0;
for (int i = 0; i < stuNum; i++) {
sumCh += scores[i][0];
sumMath += scores[i][1];
sumEng += scores[i][2];
}
double avgCh = (double) sumCh / stuNum;
double avgMath = (double) sumMath / stuNum;
double avgEng = (double) sumEng / stuNum;
System.out.printf("语文平均成绩:%.2f\n", avgCh);
System.out.printf("数学平均成绩:%.2f\n", avgMath);
System.out.printf("英语平均成绩:%.2f\n", avgEng);
for (int i = 0; i < stuNum; i++) {
double avgStu = (double) (scores[i][0] + scores[i][1] + scores[i][2]) / 3;
System.out.printf("第%d个学生的平均成绩为:%.2f\n", i + 1, avgStu);
}
}
}
阅读全文