無法輸出結果,求大家幫忙看看!
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? int stuc[]={89,-23,64,91,119,52,73}; ? ?
? ? //創建對象 ? ?
? ? HelloWorld shuchu=new HelloWorld(); ? ?
? ? //調用main方法,傳入數組參數 ? ?
? ? shuchu.print(stuc);?
? ? System.out.println("前三名的成績為:");
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void print (int [] stuc)
? ? {
? ? ? ? Arrays.sort(stuc);
? ? ? ? int num=0;
? ? ? ? for(int i=1;i>7&&num<3;i++)
? ? ? ? {
? ? ? ? ? ? if(stuc[stuc.length-i]>=0&&stuc[stuc.length-i]<=100)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? num++;
? ? ? ? ? ? ? ? System.out.println(stuc[stuc.length-i]);
? ? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? }
? ??
? ? }
??
}
2018-09-06
for(int i=1;i>7&&num<3;i++)中i>7改為i<7
2018-09-23
for循環是不是應該逆向遍歷
for(int i=stuc.length-1;i>=0;i--)
而且應該在if循環下判斷num是否大于三,若是則循環終止,輸出
2018-09-06
運行結果不顯示方法中輸出的數據, 問題出在哪里???