求大神幫我看下代碼,運(yùn)行報(bào)錯(cuò)
package zhuyong1;
import java.util.Arrays;
public class Yoo {
public static void main(String[] args) {
int[] scores={20,-52,39,96,57,45,43};
System.out.println("考試成績(jī)前三名為:");
Yoo hello=new Yoo();
hello.showTop3(scores);
}
public void showTop3(int[] scores){
Arrays.sort(scores);
int nums=0;
for(int i=scores.length-1; i>0;i--){
if(scores[0]<0||scores[i]>100){
continue;
}
nums++;
if(nums>3);{
break;
}
}
System.out.println(scores[i]);
}
}
2015-08-11
1.
System.out.println(scores[i]);
這句中的i定義是在for循環(huán)里面,而System.out.println(scores[i]);在for外面,i沒有定義。
2.
if判斷語句中scores[0] = -52,滿足<0條件了就不會(huì)往下執(zhí)行了。你最后得不到前三名的結(jié)果。
3.
我改了一下程序: