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("考试成绩的前三名为:");
hello.output(Scores);
}
//定义方法完成成绩排序并输出前三名的功能
public int[] output(int Scores[]){
int num = 0;
Arrays.sort(Scores);
for(int i=Scores.length-1;i>=0;i--){
if(Scores[i]>100||Scores[i]<0){
continue;
}
num++;
if(num>3){
break;
}
System.out.println(Scores[i]);
}
}
return Scores[];
}
return Scores;
// 引入Arrays类 import java.util.Arrays; public class HelloWorld { public static void main(String[] args) { HelloWorld hello = new HelloWorld(); int [] Scores = {89,-23,64,91,119,52,73}; int [] scores = hello.output(Scores); System.out.println("考试成绩的前三名为:"+Arrays.toString(scores)); } //定义方法完成成绩排序并输出前三名的功能 public int[] output(int Scores[]){ Arrays.sort(Scores); int[] score = new int[Scores.length]; int j = 0; for(int i=Scores.length-1;i>=0;i--){ if(Scores[i]<0 || Scores[i]>100){ continue; } score[j] = Scores[i]; j++; } int[] scores = new int[3]; for (int i=0;i<3;i++){ scores[i] = score[i]; } return scores; } }