How to displays the prompt string


Discuss the following:

Q: Provide a Java class named "Input" containing the method "readInt" (prototype given below) that displays the prompt string, reads an integer, and tests whether it is between the supplied minimum and maximum. If not, it prints an error message and repeats the entire process.

public static int readInt(Scanner in, String prompt, String error, int min, int max)

Use the following class as the main class for testing the implementation.

import java.util.Scanner;

/**
This program prints how old you'll be next year.
*/
public class AgePrinter
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int age = Input.readInt(in, "Please enter your age",
"Illegal Input--try again", 1, 150);
System.out.println("Next year, you'll be " + (age + 1));
}

Solution Preview :

Prepared by a verified Expert
JAVA Programming: How to displays the prompt string
Reference No:- TGS01934440

Now Priced at $25 (50% Discount)

Recommended (98%)

Rated (4.3/5)