马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
public class homework11 {
public static void main(String[] args) {
//Teacher teacher = new Teacher("张飞", 30, "男", 5);
//teacher.prinfInfo();
//Srudent srudent = new Srudent("小明", 15, "男", 0023015);
//System.out.println("----------------------");
//srudent.printInfo();
homework11 homework11 = new homework11();
homework11.bubbleSort(persons);
//测试
//定义多态数组,里面保存2个学生和2个教师,要求年龄从高到低排序
Person[] persons = new Person[4];
persons[0] = new Srudent("夏末", 18, "女", 002451);
persons[1] = new Srudent("姜昆", 22, "男", 004463);
persons[2] = new Teacher("张坤", 48, "男", 01);
persons[3] = new Teacher("黄花", 40, "女", 02);
}
//方法
public void bubbleSort(Person[] persons) {
Person tep = null;
for (int i = 0; i < persons.length - 1; i++) {
for (int j = 0; j < persons.length - 1 - i; j++) {
tep = persons[j];
persons[j] = persons[j + 1];
persons[j + 1] = tep;
System.out.println(persons[i]);
}
}
}
}
|