232k views
3 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 = 20:

User Tbaki
by
6.0k points

1 Answer

3 votes

Answer:

while(userNum > 1){

userNum = userNum /2;

System.out.print(userNum+" ");

}

Step-by-step explanation:

Probably don't need the print statement, but it doesn't cause an error.

In java, Write a while loop that prints userNum divided by 2 (integer division) until-example-1
User Headdab
by
5.7k points