参考大家的方法得到结果
import java.util.Arrays;
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
int[] scores = new int[]{89,-23,64,91,119,52,73};
HelloWorld hello = new HelloWorld();
hello.sort(scores);
}
//定义方法完成成绩排序并输出前三名的功能
public void sort(int[] scores)
{
/*int j = 0;
int[] realscores = new int[10];
for(int i = 0;i<scores.length;i++)
{
if(scores[i]>=0&&scores[i]<=100)
{
realscores[j] = scores[i];
j++;
}
}
Arrays.sort(realscores);
System.out.println(realscores[9]);
System.out.println(realscores[8]);
System.out.println(realscores[7]);
*/
Arrays.sort(scores);
int j = 0;
System.out.print("前三名成绩是:");
for(int i = scores.length-1;i>=0;i--)
{
if(scores[i]>=0&&scores[i]<=100)
{
System.out.println(scores[i]);
j++;
if(j>=3)
{
break;
}
}
}
}
}