求大神給找錯(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};
? ? ? ?
? ? ? ?System.out.println("前三名成績(jī)?yōu)椋?);
? ? ? ?hello.getScores(scores);
? ? ? ?
? ? ? ?
? ?}
? ?
? ?//定義方法完成成績(jī)排序并輸出前三名的功能
? ? public void getScores(int s[]){
? ? ? ? Arrays.sort(s);
? ?int c=0;
? ? ? ?for(int i=s.length;i>=0;i--){
? ? ? ? ? ?if(s[i]>=0&&s[i]<=100){
? ? ? ? ? ? ? ?c=c+1;
? ? ? ? ? ? ? ?if(c<=3){
? ? ? ? ? ? ? ?System.out.println(s[i]);
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?else
? ? ? ? ? ? ? ?break;
? ? ? ? ? ?}
? ? ? ? ? ?else
? ? ? ? ? ? ? continue;
? ? ? ?}
}
}
2016-10-24
第一處??public void getScores(int s[]) ? 括號(hào)里面 應(yīng)該是整數(shù)型數(shù)組 ?int[] ?scores
還有這里for(int i=s.length;i>=0;i--){ ?倒敘循環(huán)遍歷 ?數(shù)組開始下標(biāo)是0 ? 所以 最后一個(gè) 下標(biāo)不是 length ?應(yīng)該是
scores.length-1
2016-10-27
清晰~
2016-10-24