java - 语法错误,while/do 表达式,

标签 java compiler-errors do-while

package hw.loops.co.il;

import java.util.Scanner;

public class LoopsTargilMedium3 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int num;

        do {
            System.out.println("Please enter a number:");
            num = input.nextInt();

            if (num%2==0) {
                System.out.println("The number " + num + " is ZUGI");
            }   
            else {
                System.out.println("The number " + num + " is E-ZUGI");

                num++;
            } while (num!=-1);
            System.out.println("loop stoped");
        }
    }
}

收到此错误:

Exception in thread "main" java.lang.Error:
Unresolved compilation problem:
    Syntax error, insert "while ( Expression ) ;" to complete DoStatement 

最佳答案

您在 while 之前放错了右括号:

..
      } //<-- missing this
    }while (num!=-1);
                System.out.println("loop stoped");
...

关于java - 语法错误,while/do 表达式,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51206184/

相关文章:

c - "Undefined reference to"错误甚至函数被声明和定义

c - 回文程序,让用户选择是否要再次执行代码或不使用 do while

java - 如何连接hibernate和DB2

java - 如何将 RGB 编码和解码为十六进制

compilation - Suricata luajit 编译错误

haskell - 类型类实例检查检测不到 "piecewise instances"

java - 使用 Netbeans 创建 .jar 文件后程序停止工作

java - 在 show() 之前预加载 JavaFX 阶段

c - 提示用户重新输入号码

language-agnostic - 测试循环在顶部还是底部? (while vs. do while)