這句話什么意思hello.big3(scores)
?public static void main(String[] args) {
??? int []scores = {89,-23,64,91,119,52,79};???
???
??? System.out.println(" 本次考試前三名是:");
??? HelloWorld hello = new HelloWorld();???????
??? hello.big3(scores);???
??? }
???
??? //定義方法完成成績排序并輸出前三名的功能
???
??? public void big3(int [] scores)
??? {
??????? Arrays.sort(scores);
??????? int num = 0;
??????? for(int i = scores.length-1;i>=0&&num<3;i--)
??????? {
??????????? if(scores[i]<0||scores[i]>100)
??????????????? continue;
??????????? num++;
??????????? System.out.println(scores[i]);
??????? }
2016-07-08
hello是HelloWorld 的一個實例對象,hello.big3(scores)是指調用HelloWorld 類的方法big3,并把scores 數組作為參數傳入,其功能是,對scores 進行排序,并且在排序后輸出前3名的分數。
望采納!
2016-07-08
import?java.util.Arrays; public?class?HelloWorld?{ ?public?static?void?main(String[]?args)?{ ????int?[]scores?=?{89,-23,64,91,119,52,79};??//定義數組保存分數 ???? ????System.out.println("?本次考試前三名是:"); ????HelloWorld?hello?=?new?HelloWorld();?????//實例化對象 ????hello.big3(scores);????//將scores作為參數傳遞給big3()方法 ????} ???? ????//定義方法完成成績排序并輸出前三名的功能 ???? ????public?void?big3(int?[]?scores) ????{ ????????Arrays.sort(scores);//調用sort進行排序,默認是升序排列 ????????int?num?=?0;?//臨時變量,用來保存輸出分數的個數 ???????? ????????//初始值:i的初值為數值的最后一個元素,此時已拍好序 ????????//判斷條件:?當i>=0且num<3時還要執行循環體 ????????//i每次減一 ????????for(int?i?=?scores.length-1;i>=0&&num<3;i--) ????????{ ???????? //當分數小于0或者大于100時,因為不是正常的成績,所以使用continue跳過這次循環,進行下一次 ????????????if(scores[i]<0||scores[i]>100) ????????????????continue; ????????????num++; ????????????System.out.println(scores[i]); ????????} ????????} }2016-07-08
hello是HelloWorld這個類所創造的對象,hello.big3(scores)是指通過這個對象來調用方法,scores此時是實參傳入到方法內部