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