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

哪里错了啊

public class HelloWorld {                                                                                    

import java.util.Arrays;


    //完成 main 方法

    public static void main(String[] args) {

      int[] scores={89,-23,64,91,119,52,73};

       HelloWorld hello=new HelloWorld();

        hello.as(scores);

      System.out.println("考试成绩前三名为:") ;

        

    }

    

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

    public void as(int[]scores){

         Arrays.sort(scores);

          for (int i = scores.length - 1; i >= 0; i--) {

            if (scores[i] >= 0 &&scores[i] <= 100) {

                num++;

            } else {

                continue;

            }

            if (num > 3) {

                break;

            }

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

        }

    }

    

    

    

    

    

    

    

    

    

}


提问者:慕婉清3382415 2020-02-23 17:56

个回答

  • 生活和你
    2020-02-29 17:48:05

    没有定义num此变量

  • WE_Xing
    2020-02-25 14:24:55

    int num = 0;

  • qq_慕仰8511382
    2020-02-23 18:29:24

     hello.as(scores);

          System.out.println("考试成绩前三名为:") ;

    还有这两句顺序调换一下更好,虽然不会影响运行,但是它是按顺序输出的

  • qq_慕仰8511382
    2020-02-23 18:26:03

    你没有定义num这个变量