運(yùn)行失敗,到底錯(cuò)在哪兒
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? int[] scores={89, -23, 64, 91, 119, 52, 73};
? ? ? ? System.out.println("考試成績(jī)的前三名為:");
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ??
? ? ? ? hello.showTop3(scores);
? ? }
? ??
? ? //定義方法完成成績(jī)排序并輸出前三名的功能
? ? public void showTop3(int[] scores){
? ? ? ? Arrays.sort(scores);
? ? ? ? int num=0;
? ? ? ? for(int i=scores.length-1; i>=0;i--){
? ? ? ? ? ? if(scores[i]<0 || scores[i]>100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? num++;
? ? ? ? ? ? if(num>3){
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? }
? ? ? ??
? ? }
? ??
}
2018-10-25
你是不是文件名不是HelloWorld.java?
2018-10-20
沒(méi)問(wèn)題啊。我在eclipse上運(yùn)行的是正確的啊!
2018-10-20
break使得你的for循環(huán)直接終止,而有效成績(jī)還沒(méi)統(tǒng)計(jì)完,所以你的輸出的有效成績(jī)數(shù)目num不正確
2018-10-18
沒(méi)問(wèn)題啊