Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

use do while loop. in each iteration ask the user to neter a number greater than

ID: 644737 • Letter: U

Question

use do while loop. in each iteration ask the user to neter a number greater than 0 or 0 if they ant to quit. if they enter any number but 0 then print out whether the number is odd or even.

I have written my program but its not functioning correctly. Please help me fix my bug.

thanks

Something to do with my while expression

here's my code:

import java.util.Scanner;

public class DoWhileLoop {

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

int userNum = 0;

do {
   System.out.println("Enter a number greater than zero or Zero if you want to quit");
  
   userNum = Keyboard.nextInt();
  
   userNum = (userNum/2);
  
   if (userNum%2 == 0){  
      
       System.out.print("Number is even");
   }
  
   else
   {
  
       System.out.print("Number is odd");
      
   }

   while
      
       (userNum==(0));
   {
       System.out.print("OKay goodbye");
   }
      
}
}
}

Syntex:

Syntax error, insert "while ( Expression ) ;" to complete DoStatement


but i have already inserted by while expression.

Explanation / Answer

import java.util.Scanner;
public class DoWhileLoop {
   public static void main(String[] args) {
   Scanner Keyboard = new Scanner(System.in);
   int userNum = 0;
   do {
   System.out.println("Enter a number greater than zero or Zero if you want to quit");
   userNum = Keyboard.nextInt();
   if (userNum%2 == 0){
       System.out.print("Number is even");
   }
   else
   {
       System.out.print("Number is odd");
    }
   }while(userNum!=0);
   {
       System.out.print("OKay goodbye");
   }
}
}