Ask 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 output for userNum = 160:

+2
Answers (1)
  1. 27 November, 03:10
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers