学生成绩按总分降序,总分相同的按数学分数降序,按数学再排序不会做了
//学生成绩按总分降序,总分相同的按数学分数降序,按数学再排序不会做了public class student {
public static void main(String[] args) {
student x1 = new student("张三", 1999, 56, 65, 66, 95);
student x2 = new student("国人", 3999, 76, 65, 86, 96);
student x3 = new student("复合", 4999, 65, 50, 70, 50);
student x4 = new student("法规", 5999, 66, 75, 65, 76);
student[] xs = { x1, x2, x3, x4 };
for (int j = 0; j < xs.length; j++) {
for (int i = j; i < xs.length; i++) {
if ((xs[j].get化学() + xs[j].get数学() + xs[j].get英语() + xs[j]
.get语文()) < (xs[i].get化学() + xs[i].get数学()
+ xs[i].get英语() + xs[i].get语文())) {
student xx = xs[j];
xs[j] = xs[i];
xs[i] = xx;
}
}
}
for (int j = 0; j < xs.length; j++) {
for (int i = j; i < xs.length; i++) {
if ((xs[j].get化学() + xs[j].get数学() + xs[j].get英语() + xs[j]
.get语文()) == (xs[i].get化学() + xs[i].get数学()
+ xs[i].get英语() + xs[i].get语文())
|| (xs[j].get数学() < xs[i].get数学())) {
/*
* if (xs[j].get数学() < xs[i].get数学()) { student xx = xs[j];
* xs[j] = xs[i]; xs[i] = xx; }
*/
}
}
}// }
System.out
.println("---------------------------------------------------------------");
System.out.println("姓名\t学号\t数学\t化学\t语文\t英语\t总分\t");
for (student sp : xs) {
System.out.println(sp.get姓名() + "\t" + sp.get学号() + "\t"
+ sp.get数学() + "\t" + sp.get化学() + "\t" + sp.get语文()
+ "\t" + sp.get英语() + "\t"
+ (sp.get化学() + sp.get数学() + sp.get英语() + sp.get语文())
+ "\t");
}
}
}