請幫忙看看程序哪里錯了
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? int[] scores={89,-23,64,91,119,52,73};
? ? ? ??
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? hello.three(scores);
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void three(int[] scores){
? ? ? ? Arrays.sort(scores);
? ? ? ? int[] abc=new int[scores.length];
? ? ? ? for(int i=0,j=0;i<scores.length;i++){
? ? ? ? ? ? if(scores[i]>=0&&scores[i]<=100){
? ? ? ? ? ? ? ? abc[j]=scores[i];
? ? ? ? ? ? ? ? j++;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? System.out.println("考試成績的前三名為:");
? ? ? ? ?for(;j>abc.length-3;j--){
? ? ? ? ? ? System.out.println(abc[j]);
? ? ? ? }
}
}
? ??
2015-04-06
j定義在了for循環(huán)里,在后面好像不能用他.
abc[j]也是在循環(huán)里被賦值,輸出abc[j]時只是個空數(shù)組.
我也是初學者,說錯了請指正,謝謝