求大神告知這套代碼中的錯(cuò)誤
import java.util.Arrays;
public class HelloWorld {
public static void main(String[] args) {
int[]scores= {89,-23,64,91,119,52,73};//定義一個(gè)數(shù)組保存成績(jī)
System.out.print("考試成績(jī)的前三名為:");
HelloWorld hello=new HelloWorld();//定義對(duì)象
hello.Top3(scores);//調(diào)用方法保存數(shù)組
}
public void Top3(int[]scores){
? ? ? ?Arrays.sort(scores);
? ? ? ?int num=0;
? ? ? ?for(int i=scores.length-1;i>=0&&i<3;i--){
? ? ? ? ? ?if(scores[i]<0||scores[i]>100)?
? ? ? ? ? ? ? ?continue;
? ? ? ? ? ?num++;
? ? ? ? ? ?System.out.print(scores[i]+" ");
? ? ? ?}
? ?}
}
2017-11-29
你這個(gè)i的賦值是咋回事?數(shù)組八個(gè)數(shù),初始的i值是7。你的條件是i<3的時(shí)候i--。所以就錯(cuò)了
2017-12-25
i>=0&&i<3這不矛盾了莫,后面是num<3就對(duì)了。
2017-11-30
i>=0&&i<3 ? 這個(gè)的問(wèn)題 ?i的條件判斷
2017-11-29
2017-11-29
相當(dāng)于i一直沒(méi)有自減