Ilana Zhadan
Ilana Zhadan

Reputation: 1

syntax error , while/do expression,

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");
        }
    }
}

Receiving this error:

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

Upvotes: 0

Views: 871

Answers (3)

Vishal Sharma
Vishal Sharma

Reputation: 1061

please check do while loop syntax
//--------------------------
do {
     // statements
} while (expression);

---------------------//


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");



    }
}

Upvotes: 0

Dinesh
Dinesh

Reputation: 1086

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++;
            } 
            System.out.println("loop stoped");
        }while (num!=-1);
    }

}

Upvotes: 1

apomene
apomene

Reputation: 14389

you have misplaced a closing bracket before while:

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

Upvotes: 1

Related Questions