import java.util.Arrays ;public class HelloWorld {? ? //完成 main 方法? ? public static void main(String[] args) {? ? ? ?? ? ? ? int[] scores = {89,-23,64,91,119,52,73};//數(shù)組? ? ? ? System.out.println("前三名的成績:");//輸出? ? ? ? HelloWorld ?hello = new ?HelloWorld() ; //建對象? ? ? ? hello.three(scores);//調(diào)用方法,傳入數(shù)組? ?? ? }? ??? ? //定義方法完成成績排序并輸出前三名的功能? ? ? ?public void three (int[] scores){? ? ? ? ? ?Arrays.sort(scores);//排序? ? ? ? ? ?int num = 0; //保存有效成績的數(shù)量? ? ? ? ? ?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]);? ? ? ?}? ? ? ? ? ?}? ? ? ?? ? }? ? ?? ??}
為什么這個num一直報錯
ThreeAgain
2017-06-28 17:50:57