创建一个对象数组,数组的元素是学生,学生的信息包括学号、姓名和成绩,在main函数之中将数组中大于80分的学生信息显示出来
时间: 2023-04-07 15:05:05 浏览: 103
可以使用以下代码创建一个学生类,然后创建一个学生对象数组,遍历数组,将成绩大于80分的学生信息打印出来:
```
class Student {
private String id;
private String name;
private int score;
public Student(String id, String name, int score) {
this.id = id;
this.name = name;
this.score = score;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public int getScore() {
return score;
}
}
public class Main {
public static void main(String[] args) {
Student[] students = new Student[5];
students[0] = new Student("001", "张三", 78);
students[1] = new Student("002", "李四", 85);
students[2] = new Student("003", "王五", 92);
students[3] = new Student("004", "赵六", 79);
students[4] = new Student("005", "钱七", 88);
for (Student student : students) {
if (student.getScore() > 80) {
System.out.println("学号:" + student.getId() + ",姓名:" + student.getName() + ",成绩:" + student.getScore());
}
}
}
}
```
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)