Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the do-while loop to output 0 to countLimit. Assume the user will only

ID: 672320 • Letter: C

Question

Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number.

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;
}
}

Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number.

Explanation / Answer

Solution is given as below:

} while ( printVal <= countLimit );

Note: Following statement can be used to get the input after // Get user input

System.out.println("Please enter a Positive Integer:");