In: Computer Science
*JAVA PROGRAM*
Write a do loop that prompts a user to enter an integer between 1 and 100 inclusive. The user will be repeatedly prompted until they input a valid integer.
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
//importing packages
import java.util.*;
public class Main
{
public static void main(String[] args) {
//Scanner is used to take inputs
from the user
Scanner scnr = new
Scanner(System.in);
//initializing integer
variable
int i;
//starting do while loop
do
{
System.out.print("Enter a Number
between 1 and 100: ");
//getting integer input from the
user
i = scnr.nextInt();
//do while will iterate
//if i value is less than 1 or
greater than 100
//do while will stop iterate
//if i value is in between 1 and
100 inclusive
}while(i < 1 || i >
100);
}
}
//code ended here
Output:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!