视频
笔记
(1)定义学生类Student
声明姓名和成绩成员变量
(2)测试类ObjectArrayTest的main中创建一个可以装3个学生对象的数组,并且按照学生成绩排序,显示学生信息
public class Student { private String name; private int score; public Student() { } public Student(String name, int score) { this.name = name; this.score = score; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getScore() { return score; } public void setScore(int score) { this.score = score; } }
public class Demo02ObjectArray { public static void main(String[] args) { Student[] students = new Student[3]; students[0] = new Student("金莲",26); students[1] = new Student("大郎",50); students[2] = new Student("涛哥",18); for (int j = 0; j < students.length-1; j++) { for (int i = 0; i < students.length-1-j; i++) { if (students[i].getScore()>students[i+1].getScore()){ Student temp = students[i]; students[i] = students[i+1]; students[i+1] = temp; } } } for (int i = 0; i < students.length; i++) { System.out.println(students[i].getName()+"..."+students[i].getScore()); } } }