調(diào)用方法的參數(shù)為Arrays.sort(scores);為什么不行,這個(gè)代碼為什么錯(cuò)了
import java.util.Arrays;
public class HelloWorld {?
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? int[] scores={89,-23,64,91,119,52,73};
? ? ? ? hello.chengji( Arrays.sort(scores); );? ? ? ??? ? ? ??
? ? }??
? ? //定義方法完成成績(jī)排序并輸出前三名的功能??
? ? public void chengji(int[] score){? ??
? ? ? ?int count=0;
? ? ? ? for(int i=score.length-1;i>=0;i--){? ?
? ? ? ? ? ? if(score[i]<0||score[i]>100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }else if(count<3){
? ? ? ? ? ? ? ? count++;
? ? ? ? ? ? ? ? System.out.println("考試成績(jī)的前三名是"+score[i]);
? ? ? ? ? ? System.out.println("前三名的數(shù)量"+count);? ?
? ? ? ? ? ? }??
? ? ? ? }??
? ? }? ??
}
2015-03-09
Arrays.sort(scores); 這個(gè)的返回類型是空,你怎么能拿它傳入你定義的chenji()方法里呢?你對(duì)這個(gè)包不熟悉而且代碼格式應(yīng)該寫好看點(diǎn).