小编Ven*_*nto的帖子

如果在while循环内,则不能突破while循环

我最近开始学习Java并在测试时发现了一个问题.这可能是一个非常简单的问题,但我似乎无法解决它.这是我的代码:

    int firstj = 1;

    if (firstj == 1) {
        String choice = "Type a number between 1 and 4";
        System.out.println(choice);
        while (true) {

            if (firstj == 1) {
                Scanner third = new Scanner(System.in);
                String thirdch = third.nextLine();

                while (true) {

                    if (thirdch.equals("1")) {
                        System.out.println("Show choice and accept input again ");
                        System.out.println(choice);
                        break;
                    } else if (thirdch.equals("2")) {
                        System.out.println("Show choice and accept input again ");
                        System.out.println(choice);
                        break;
                    } else if (thirdch.equals("3")) {
                        System.out.println("Show choice and accept input again ");
                        System.out.println(choice); …
Run Code Online (Sandbox Code Playgroud)

java loops if-statement break while-loop

3
推荐指数
2
解决办法
813
查看次数

标签 统计

break ×1

if-statement ×1

java ×1

loops ×1

while-loop ×1