问答详情
源自:7-1 编程练习

交作业,继续进行第二季

第一季的最后一章作业,继续下一季。加油~

https://img4.mukewang.com/5bf6006700016fed09100665.jpg

提问者:花書畫 2018-11-22 09:05

个回答

  • 独步江湖2018
    2018-11-22 14:58:51

    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.big3(scores);    

        }

        

        //定义方法完成成绩排序并输出前三名的功能

        

        public void big3(int [] scores)

        {

            Arrays.sort(scores);

            int num = 0;

            for(int i = scores.length-1;i>=0&&num<3;i--)

            {

                if(scores[i]<0||scores[i]>100)

                    continue;

                num++;

                System.out.println(scores[i]);

            }

        }

        

        

        

        

        

        

        

        

    }