Java编程实现:输入10名学生某一门课的成绩(满分100分),统计10名学生该课程的平均分、优秀人数(成绩不低于90分)、及格人数(成绩不低于60分)、及格率并输出
时间: 2024-10-09 15:05:21 浏览: 57
在Java编程中,你可以创建一个简单的程序来实现这个功能。首先,可以定义一个`Student`类,包含姓名和成绩属性,然后创建一个数组或列表来存储10名学生的信息。接下来,我们编写一个主函数来收集输入,计算并输出所需的统计数据。
```java
import java.util.ArrayList;
import java.util.Scanner;
class Student {
String name;
int score;
public Student(String name, int score) {
this.name = name;
this.score = score;
}
@Override
public String toString() {
return "Name: " + name + ", Score: " + score;
}
}
public class CourseGradeStatistics {
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
// 输入10名学生的成绩
for (int i = 0; i < 10; i++) {
System.out.println("Enter student " + (i+1) + "'s name and score:");
String name = scanner.nextLine();
int inputScore = scanner.nextInt();
students.add(new Student(name, inputScore));
}
scanner.close();
// 计算平均分、优秀人数、及格人数和及格率
int totalScore = 0;
int excellentCount = 0;
int passCount = 0;
for (Student student : students) {
totalScore += student.score;
if (student.score >= 90) {
excellentCount++;
} else if (student.score >= 60) {
passCount++;
}
}
double averageScore = (double) totalScore / students.size();
double passRate = (passCount * 100.0) / students.size();
System.out.println("Average score: " + averageScore);
System.out.println("Number of students with scores >= 90 (Excellent): " + excellentCount);
System.out.println("Number of students with scores >= 60 (Passing): " + passCount);
System.out.println("Passing rate: " + passRate + "%");
}
}
```
当你运行这个程序,它会提示用户逐个输入学生的姓名和分数,并在结束后显示相应的统计结果。
阅读全文