62,628
社区成员
发帖
与我相关
我的任务
分享TreeSet<Student> ts = new TreeSet<Student>();
ts.add(new Student("王3" , 100));
ts.add(new Student("王4" , 100));
ts.add(new Student("王2" , 80));
ts.add(new Student("王1" , 60));
List<Student> list = new ArrayList<>();
list.addAll(ts);
int mingCI = 0;
for(int i = 0; i < list.size(); i++) {
//如果不是第一个且上一名成绩和当前的相等时
mingCI++;
if(i != 0 && i != 0 && list.get(i - 1).score == list.get(i).score) {
mingCI--;
System.out.println("并列第" + mingCI + "名;" + list.get(i));
} else {
System.out.println("第" + mingCI + "名;" + list.get(i));
}
}
谢谢