感覺(jué)代碼沒(méi)問(wèn)題,但老是報(bào)錯(cuò),麻煩幫我看一下。
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? System.out.println("考試成績(jī)的前三名為:");
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? int[] scores={89,-23,64,91,119,52,73};
? ? ? ? hello.top(scores);
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績(jī)排序并輸出前三名的功能
? ? public void top(int[] scores){
? ? ? ? Arrays.sort(scores);
? ? ? ? int count=0;
? ? ? ? for(int i=scores.length;i>=0;i--){
? ? ? ? ? ? if(scores[i]<0||scores[i]>100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? count++;
? ? ? ? ? ? if(count<=3){
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ? }
? ? ? ? }
? ? }
2019-07-28
int i=scores.length-1