99999
99999999
99999999
2018-10-10
public static void main(String[] args) {
HelloWorld hello=new HelloWorld();
int scores[]={89,-23,64, 91 , 119 , 52 , 73};
hello.sortScores(scores);
}
//定义方法完成成绩排序并输出前三名的功能
public void sortScores(int scores[]){
int num=0;
int m=0;
for (int i=0;i<scores.length;i++){
if(scores[i]<=100&&scores[i]>=0){
num++;
}
}
int scores1[]=new int[num];
for (int i=0;i<scores.length;i++){
if(scores[i]<=100&&scores[i]>=0){
scores1[m]=scores[i];
m++;
}
}
Arrays.sort(scores1);
System.out.println("考试成绩前三名为:");
System.out.println(scores1[m-1]);
System.out.println(scores1[m-2]);
System.out.println(scores1[m-3]);
}
举报