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

怎么错了,报错郁闷啊

error: unreachable statement
num ++;
^
1 error

提问者:1316478248 2015-01-13 13:08

个回答

  • 伊兮尘昔
    2015-01-13 13:29:18
    已采纳

    continue之后能跟语句吗?

  • _Exception
    2015-01-13 16:38:31

    public class HelloWorld {

        // 完成 main 方法

        public static void main(String[] args) {

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

            HelloWorld hello = new HelloWorld();

            hello.scoresSort(scores);

        }

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

        public void scoresSort(int[] scores) {

            Arrays.sort(scores);

            int num = 0;

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

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

                    num++;

                    continue;

                }

                if (num > 3) {

                    break;

                }

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

            }

        }

    }