getinfo();
}
public void getinfo()
{
System.out.println("name="+name+" age="+age+" list="+list);
}
}
class Studentinfo
{
public static void main(String[] args)
{
Student s1 = new Student("xiaohua",23,66);
Student s2 = new Student("xiaojun",20,85);
Student s3 = new Student("xiaoli",20,35);
Student s4 = new Student("xiaoming",20,78);
Student s5 = new Student("xiaolan",20,100);
}
}作者: 祁焱 时间: 2012-1-13 13:52
代码仅供参考,关键是理解排序的过程,建议你把学生对象存放到数组中,这样操作起来比较方便:
Student[] stu = new Student[5];//创建数组对象
stu[0] = new Student("张三", 19, 88);
stu[1] = new Student("李四", 21, 79);
stu[2] = new Student("王五", 28, 90);
stu[3] = new Student("张六", 17, 91);
stu[4] = new Student("陈七", 23, 99);
for (int i = 1; i < stu.length; i++) {//采用冒泡法排序,外层循环表示总循环趟数
for (int j = 0; j < stu.length - i; j++) {//内层循环表示每趟循环次数
if (stu[j].getScore() > stu[j + 1].getScore()) {
Student s = null;
s = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = s;
}
} 作者: 刘基军 时间: 2012-1-13 14:44
元素Student实现Comparable接口,重写compareTo()方法,存储于TreeSet集合