這對么?盡管通過了但是我還是不太懂,求師兄指教
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? int scores[]={89,-23,64,91,119,52,73};
? ? ? ? HelloWord hello=new HelloWord();
? ? ? ? hello.top3(scores)
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ??
? ? public void top3(int[] nums){
? ? Arrays.sort(nums);
System.out.println("考試前三名為: ");
? ? HelloWorld hello =new HelloWorld();
for(int i = nums.length-1; i>=top; i--){
if(nums[i]>=0 && nums[i]<=100){
System.out.println(nums[i]);
int top[2];
int o=0;for(q=0;q<=2;q++){
for(i=0,top[q]=num[0],i!=o;i<=num.length-1;i++){
? ? if(top[q]<mum[i])top[q]=num[i];o=i
}
System.out.println(+top[q]);
}
}
} ?
}
}
? ??
? ??
? ??
? ??
? ??
? ??
2015-12-25
我也是新手,互相學習。
我感覺你這邏輯有點亂,可能是我看的還不是太明白。
//?main方法里的沒錯。 //?top3()方法中 //?首先對數組進行排序。這里沒錯。 Arrays.sort(nums); //?然后我們還需要定義個參數,來保存我們已經輸出了多少數字,因為我們只要前三,輸出三個就夠了。 int?k?=0; //?然后就是循環 for(int?i=0;i<nums.length(),k<3;i++){????????//?當i<數組的長度和K<3時繼續循環。這樣就OK了 System.out.println(nums[i]);????????//?這樣你輸出三個數就行了。 k++; }