170,986 views
35 votes
35 votes
In Java, write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum = 40:

20 10 5 2 1

In Java, write a while loop that prints userNum divided by 2 (integer division) until-example-1
User Ridalgo
by
2.8k points

1 Answer

11 votes
11 votes

Answer:

The pseudocode is in the explanation.

Step-by-step explanation:

First, start with the user input.

user_input=scanner.next()

while user_input is not 1: ==> if the input is 1, the while loop wouldn't run

print(user_input/2+" ") ==> first print the input/2: Ex: If input=40, print 20

Also, remember to include the space

user_input/=2 ==> change the user_input by dividing it by 2 everytime

User Mostafa Wael
by
3.0k points