0
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 
2
  • 2
    As your indentation indicates, you have while inside the do block, not at the end of it. Commented Jul 6, 2018 at 8:36
  • 3
    You are not doing a do-while, you are doing an if-else-while . Commented Jul 6, 2018 at 8:36

3 Answers 3

1

you have misplaced a closing bracket before while:

..
      } //<-- missing this
    }while (num!=-1);
                System.out.println("loop stoped");
...
Sign up to request clarification or add additional context in comments.

1 Comment

Not quite "miss", the number tallies, but the position is wrong.
1
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);
    }

}

1 Comment

I don't think "loop stoped" is supposed to be inside the loop.
0
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");



    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.