ajjrx丶
2016-07-12 19:48:14浏览 3099
import java.util.Arrays;
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
int []scores = {89,-23,64,91,119,52,79};
System.out.println(" 本次考试前三名是:");
HelloWorld hello = new HelloWorld();
hello.sortInput(scores);
}
//定义方法完成成绩排序并输出前三名的功能
public void sortInput(int [] scores)
{
Arrays.sort(scores);
for(int i = scores.length-1,j = 0;i>=scores.length-4;--i,++j)
{
if(scores[i]>=0&&scores[i]<=100) {
System.out.println("第" + j + "名:" + scores[i]);
}
}
}
}