Question: Ready for Takeoff! This code sample has a do while loop that prints the count from num down to 1 . Although the code compiles

Ready for Takeoff!
This code sample has a do while loop that prints the count from num down to 1. Although the code compiles and runs, it does not return the expected result.
Identify the bug and fix it.
If the value of num is 5, then this is what the result should be:
The count is: 5 The count is: 4 The count is: 3 The count is: 2 The count is: 1
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class findTheBug {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int num = in.nextInt();
// FIX THE CODE BELOW THIS LINE
int count =0;
do {
System.out.println("The count is: "+ count);
count--;
} while (count < num);
}
}
STDOUT
Expected STDOUT
Thecountis:5
Thecountis:4
Thecountis:3
Thecountis:2
Thecountis:1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!