import java.util.*;
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
int[] scores = {89,-23,64,91,119,52,73};
TopE(scores);
}
//定义方法完成成绩排序并输出前三名的功能
public static void TopE(int[] in) {
int count = 0;
int[] ab = new int[3];
int j = 0;
try{
for(int i = in.length; i >= 0; i--) {
if(in[i]>0 && in[i]<100) {
ab[j++] = in[i];
count++;
if(count > 3)
break;
}else {continue;}
}
}catch (Exception e) {}
System.out.println("考试成绩的前三名为:");
Arrays.sort(ab);
System.out.println(Arrays.toString(ab));
}
}
package com.imooc;
import java.util.Arrays;
import java.util.Scanner;
public class HelloWord {
public static void main(String[] args){
HelloWord hello=new HelloWord();
int[] scores={89 , -23 , 64 , 91 , 119 , 52 , 73};
System.out.println("考试的前三名为:");
hello.third(scores);
}
public void third(int[] scores) {
// TODO Auto-generated method stub
Arrays.sort(scores);
int count=0;
for(int i=scores.length-1;i>=0;i--){
if(scores[i]<0||scores[i]>100) continue;
count++;
if(count<=3) System.out.println(scores[i]);
}
}
}