Ask Question
12 July, 21:01

Write a while loop that prints userNum divided by 4 (integer division) until reaching 2 or less. Follow each number by a space. Example output for userNum = 160:

+3
Answers (1)
  1. 12 July, 23:37
    0
    Following are the Program in Java Language

    import java. util.*; / / import package

    public class Main / / Main class

    {

    public static void main (String[]args) / / main method

    {

    int userNum; / / variable decleration

    Scanner sc2=new Scanner (System. in); / / creating the instance of scanner class

    System. out. print (" Enter the number:");

    userNum=sc2. nextInt (); / / Read the number by user

    while (userNum/4 > = 2) / / iterating the while loop

    {

    userNum = userNum/4;

    System. out. print (userNum); / / display number

    System. out. print (" ");

    }

    }

    }

    Output:

    Enter the number:160

    40 10 2

    Explanation:

    Following are the description of the Program

    Read the number in "userNum" of int type by using the instance of scanner class. Iterating the while loop divided by the until the reaching value of less then 2 In that while loop print the value of userNum.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a while loop that prints userNum divided by 4 (integer division) until reaching 2 or less. Follow each number by a space. Example ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers