In the program While loop is used. In the while loop it divides the userNum by 2 in each iteration and prints the value of userNum. The inputs and corresponding outputs are written in the explanation.
<u>Explanation</u>:
In the while loop it divides the userNum by 2 in each iteration and prints the value of userNum.
import java.util.Scanner;
public class NonNegativeLooper
public static void main (String [] args)
Scanner scnr = new Scanner(System.in);
//initialize the userNum with 9
int userNum = 9;
//Repeat the loop until the userNum is not negative
while (userNum>=0)
System.out.println(Body);
//Prompt the user to enter the usrNum again
userNum = scnr.nextInt();
System.out.println(Done.);
return;