Ask Question
19 March, 10:13

7.7 LAB: Using a while loop countdown Write a program that takes in an integer in the range 10 to 100 as input. Your program should countdown from that number to 0, printing the count each of each iteration. After ten numbers have been printed to the screen, you should start a newline. The program should stop looping at 0 and not output that value. I would suggest using a counter to count how many items have been printed out and then after 10 items, print a new line character and then reset the counter. important: Your output should use " %3d " for exact spacing and a space before and after each number that is output with newlines in order to test correctly.

+5
Answers (1)
  1. 19 March, 10:50
    0
    The solution is written in Java

    public class Main { public static void main (String[] args) { int count = 0; Scanner stream = new Scanner (System. in); System. out. print ("Input a number between 10 to 100: "); int num = stream. nextInt (); while (num > 0) { if (count % 10! = 0) { System. out. printf ("%3d", num); }else{ System. out. println (); System. out. printf ("%3d", num); } count++; num--; } } }

    Explanation:

    Firstly create a counter variable, count and initialize it with zero (Line 3).

    Next, create Scanner object and prompt the user to input a number between 10 to 100 (Line 4-6).

    Create a while loop and set the loop condition as while the count down number is still bigger than zero, the loop should keep going on (Line 8). Next, create an if condition to check if the counter variable reach multiple of 10 times. If not print the current num or else create a new line and then only print the current num (Line 9 - 14).

    Increment the count by one and decrements the num by one before running the next iteration (Line 15 - 16).
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “7.7 LAB: Using a while loop countdown Write a program that takes in an integer in the range 10 to 100 as input. Your program should ...” 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