請指出我的錯誤在哪里,謝謝
import java.util.Arrays; ? //導入Arrays類
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ? int[] scores={89,-23,64,91,119,52,73};
? ? ? ? System.out.print("前三名:");
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? hello.top3(scores); ? //調用方法,傳入數(shù)組
? ? }
? ??
? ? public void top3(int[] scores){
? ? ? ? Arrays.sort(scores); ?//對數(shù)組排序
? ? ? ? for(int i=0;i<3;i++){
? ? ? ? ? ? System.out.print(scores[0],scores[1],scores[2]); ??//遍歷數(shù)組,將前三位輸出
? ? ? ? ? ? }
? ? ? ? }
}
2018-01-09
for循環(huán)寫的不對可以參考那個倒敘的循環(huán),還需要判斷if..再看看別人的代碼,理解下,然后根據(jù)自己的思路寫下
2018-01-09
Arrays.sort()是升序排列,所以循環(huán)時應該倒著遍歷,并且需要加個判斷語句去掉小于0或大于100的分數(shù),仔細看練習提示內容,里面講的很詳細。
2018-01-09
wuyu!