运行失败,提示第三行错误
public class HelloWorld {
import java.util.Arrays;
//完成 main 方法
public static void main(String[] args) {
HelloWorld test = new HelloWorld();
int[] scores = {82, -23, 63, 91, 119, 52, 73};
int[] topThree = test.getTopThree(scores);
System.out.println("前三名为:");
for (int i : topThree){
System.out.println(i);
}
}
//定义方法完成成绩排序并输出前三名的功能
public int[] getTopThree(int[] scores){
Arrays.sort(scores);
int top = 1;
int[] topThree = new int[3];
for (int i = (scores.length) - 1; i >= 0; i--){
if (top > 3){
break;
}else{
topThree[(topThree.length) - 1 - i] = scores[i];
}
return topThree;
}
}