基础的编程题——成绩排序筛选有条件输出。(java)


程序代码

mport java.util.Arrays;


public class hello {


public static void main(String[] args) {

        int scores[]={89,-23,64,91,119,52,73};
        System.out.println("考试的前三名是:");
        hello hh=new hello();
       hh.showtop3(scores);
}
public void showtop3(int[] scores){
        Arrays.sort(scores);
        int n=0;
        int i;
        for(i=scores.length-1;i>=0;i--){
            if(scores[i]<0||scores[i]>100){
                continue;
            }n++;
            if(n>3){
                break;
            }
            System.out.println(scores[i]);
        }
    }
    


}


结果:成绩前三名是:91

                                  89

                                  73


猜你喜欢

转载自blog.csdn.net/yezongzhen/article/details/80316306