慕婉清3382415
2020-02-23 17:56
public class HelloWorld {
import java.util.Arrays;
//完成 main 方法
public static void main(String[] args) {
int[] scores={89,-23,64,91,119,52,73};
HelloWorld hello=new HelloWorld();
hello.as(scores);
System.out.println("考试成绩前三名为:") ;
}
//定义方法完成成绩排序并输出前三名的功能
public void as(int[]scores){
Arrays.sort(scores);
for (int i = scores.length - 1; i >= 0; i--) {
if (scores[i] >= 0 &&scores[i] <= 100) {
num++;
} else {
continue;
}
if (num > 3) {
break;
}
System.out.println(scores[i]);
}
}
}
没有定义num此变量
int num = 0;
hello.as(scores);
System.out.println("考试成绩前三名为:") ;
还有这两句顺序调换一下更好,虽然不会影响运行,但是它是按顺序输出的
你没有定义num这个变量
Java入门第一季(IDEA工具)升级版
1167144 学习 · 17968 问题
相似问题