當前位置:成語大全網 - 書法字典 - Java排序問題?

Java排序問題?

如果有幫助,請采納。如果名字相同,暫時按總分最高輸出,閱讀順序不變。

導入Java . util . arrays;

導入Java . util . scanner;

班級學生實現可比& lt學生& gt{

字符串名稱=““;

int score English = 0;

int score computer = 0;

@覆蓋

公共國際比較(學生){

if(this . name . compare to(s . name)& lt;0){

返回-1;//升序;

}

else if(this . name . compare to(s . name)& gt;0){

返回1;

}

否則{

return(s . score English+s . score computer)-(this . score English+this . score computer);

}

}

@覆蓋

公共字符串toString(){

返回“student {“+

“name =‘“+name+‘\‘“+

“,score English =“+score English+

“,score computer =“+score computer+。

'}';

}

}

公共類排序{

公共靜態void main(String[] args) {

Scanner sc =新掃描儀(system . in);

student【】stu =新學生【5】;

for(int I = 0;我& lt5;i++){

stu【I】=新學生();

斯圖【我】。name = sc . next();

斯圖【我】。score English = sc . nextint();

斯圖【我】。score computer = sc . nextint();

}

arrays . sort(stu);

for(int I = 0;我& lt5;i++){

system . out . println(stu【I】。toString());

}

}

}