酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

Java 实现:5 名学生三门课成绩统计,揭秘最高分、最低分及每人平均分!

以下是一个使用 Java 语言解决此问题的示例代码: ```java import java.util.Scanner; public class StudentScoreAnalysis { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] studentNames = {"张三", "李四", "王五", "赵六", "孙七"}; String[] courseNames = {"语文", "数学", "英语"}; double[][] scores = new double[5][3]; // 输入学生成绩 for (int i = 0; i < 5; i++) { System.out.println("请输入" + studentNames[i] + "的成绩:"); for (int j = 0; j < 3; j++) { System.out.print(courseNames[j] + "成绩:"); scores[i][j] = scanner.nextDouble(); } } double maxScore = Double.MIN_VALUE; double minScore = Double.MAX_VALUE; String maxStudent = ""; String maxCourse = ""; String minStudent = ""; String minCourse = ""; double[] averageScores = new double[5]; // 计算最高分、最低分、每个学生的平均分 for (int i = 0; i < 5; i++) { double sum = 0; for (int j = 0; j < 3; j++) { sum += scores[i][j]; if (scores[i][j] > maxScore) { maxScore = scores[i][j]; maxStudent = studentNames[i]; maxCourse = courseNames[j]; } if (scores[i][j] < minScore) { minScore = scores[i][j]; minStudent = studentNames[i]; minCourse = courseNames[j]; } } averageScores[i] = sum / 3; } // 输出结果 System.out.println("最高分:" + maxScore + ",学生:" + maxStudent + ",课程:" + maxCourse); System.out.println("最低分:" + minScore + ",学生:" + minStudent + ",课程:" + minCourse); for (int i = 0; i < 5; i++) { System.out.println(studentNames[i] + "的平均成绩:" + averageScores[i]); } scanner.close(); } } ``` 在上述代码中,首先定义了学生姓名和课程名称数组,然后创建了一个二维数组来存储学生的成绩。通过循环输入成绩,并在输入过程中计算最高分、最低分和每个学生的总分。最后计算平均分并输出所有结果。 ######[AI写代码神器 | 625点数解答 | 2024-11-14 08:46:24]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]