Complete the do-while loop to output from 0 to the value of countLimit using printVal. Assume the user will only input a positive number. For example, if countLimit is 5 the output will be:
0
1
2
3
4
5
import java.util.Scanner;
public class CountToLimit {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int countLimit = 0;
int printVal = 0;
// Get user input
countLimit = scnr.nextInt();
printVal = 0;
do {
System.out.print(printVal + " ");
printVal = printVal + 1;
} while ( /* Your solution goes here */ );
System.out.println("");
return;
}
}

Respuesta :

Answer:

Replace

while ( /* Your solution goes here */ );

with

while (printVal <=countLimit );

Explanation:

while (printVal <=countLimit );

This checks if the printVal is less than or equal to countLimit.

While this statement is true, the program will continue printing the required output

See attachment for complete program

Ver imagen MrRoyal