As a website developer I would like an error message to be output to the console if the number of pages is invalid.The number of pages must be greater than 1 and less than 1000.
How would I write this in java. Please help.
Java code:
import java.util.Scanner;
public class Main
{
//main function
public static void main(String[] args) {
//creating Scanner Object page_input
Scanner page_input=new Scanner(System.in);
//variable for storing page input
int num;
//asking for number of pages
System.out.println("Enter the number of pages: ");
//accepting number of pages
num=page_input.nextInt();
//checking if number of pages is invalid
if(num<=1 || num>=1000)
//printing invalid number of pages
System.out.println("Invalid number of pages.");
}
}
Screenshot:
Input and Output:
Get Answers For Free
Most questions answered within 1 hours.