大佬幫我找找哪兒有問題?
import java.util.Arrays;//導入類
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? //定義一個對象
? ? ?HelloWorld hello=new HelloWorld();? ? ? ? ? ? ? ??
? ? ?//創(chuàng)建一個整型數組保存成績
? ? int scores[]={89 , -23 , 64 , 91 , 119 , 52 , 73}
? ? ?System.out.println(" 本次考試前三名是:");
? ? ?/*調用并接收方法的返回值
? ? ? 將cjFf方法的返回值保存到scor數組
? ? ?*/
? ? ? ? int scor[]=hello.cjFf(scores);?
? ? ? ??
? ? ?for(int y=0;y>2;y++){ //遍歷接收返回值的數組
? ? ?
? ? ? ? System.out.println(scor[y]) //分別輸出返回數組的每個值
? ? ?}
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public static int[] cjFf(int[] scores){? ? //創(chuàng)建一個cjFf方法參數為scores數組
? ??
? ? ? ? int a=0;? ? //用于記錄有效成績數量
? ? ? ??
? ? ? ? ?Arrays.sort(scores);? ?//將數組scores排序
? ? ? ? ?
? ? ? ? ?int score=new int[2];? ?//新建一個int型數組用于返回值
? ? ? ? ?
? ? ? ? ?for(int i=scores.length-1;i>=0;i--){? ?//從大到小的順序遍歷scores數組
? ? ? ? ?
? ? ? ? ? ? ?if(a=3){? ? ?//判斷有效成績是否已經滿足3個
? ? ? ? ? ? ?
? ? ? ? ? ? ? continue;? ? ?//滿足直接跳出for循環(huán)
? ? ? ? ? ? ??
? ? ? ? ? ? ?}
? ? ? ? ? ? ?else? ?//不滿足繼續(xù)賦值
? ? ? ? ? ? ?
? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ?if(scores[i]<0||scores[i]>100)? //判斷數組的成績滿足要求不
? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ?score[a]=scores[i];? ?//滿足要求將數組的值賦予將返回的數組
? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ?a=a+1;? ?//有效成績加一
? ? ? ? ? ? ? ??
? ? ? ? ? ? ?}
? ? ? ? ? ? ?
? ? ? ? ?}
? ? ? ? return score;//將數組返回
? ? ? ??
? ? }
? ??
}
2018-06-06
新建一個int型數組用于返回值
int score=new int[3]; ??
2018-06-08
看圖片。