Ask Question
19 June, 03:32

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:

+5
Answers (1)
  1. 19 June, 07:00
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers