Question

As a website developer I would like an error message to be output to the console...

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.

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
You must use Windows Programming(Do NOT use Console) to complete this assignment. Use any C# method...
You must use Windows Programming(Do NOT use Console) to complete this assignment. Use any C# method you already know. Create a Windows application that function like a banking account register. Separate the business logic from the presentation layer. The graphical user interface should allow user to input the account name, number, and balance. Provide TextBox objects for withdrawals and deposits. A button object should be available for clicking to process withdrawal and deposit transactions showing the new balance. Document and...
I would like the answer for this question in 3-4 pages and from a "personal" point...
I would like the answer for this question in 3-4 pages and from a "personal" point of view. (i.e.: the data in your life that is not business).Think about all of your personal data. All of your hard drives, cloud storage, smart phones, data cds, email, pictures, music, video etc... 1) Assess your risk. How sensitive is your most sensitive data. What do you currently do to protect it? Is this enough? What would happen if the data were compromised?...
The p-value is greater than the significance level. (a) We can have a Type I error...
The p-value is greater than the significance level. (a) We can have a Type I error (b) The absolute value of the test statistic is less than the absolute value of the t critical value (c) If we had used a larger value for alpha the p-value would have been smaller (d) We must have had a two tail test
I am seeing a few different answers for this question, so I would like to confirm...
I am seeing a few different answers for this question, so I would like to confirm the correct one. Please don't copy from the other ones on here as I am trying to get the correct answer. Thanks! A student is required to answer 10 out of 13 questions. Find the number of possible choices if the student must answer: (b) the first or second question, but not both
So I would like to multiply a first digit by 2. I have to randomize either...
So I would like to multiply a first digit by 2. I have to randomize either 51-55 but multiply that first digit by 2 whichever the number may come out to be. I also need to keep the string. I need this to be in JAVA but so far Here is my code: import java.util.Random; public class Randoms {    public static void main(String[] args) {    Random rng = new Random();    String x;    int max = 55;...
I have created images that I would like to have placed where the message is revealed?...
I have created images that I would like to have placed where the message is revealed? What is the best way to make it work. I tried to make it work and have not had much success. My images are saved as png's. Here is my original code. <!Doctype html> <html> <head> <meta charset="UTF-8"> <title>Dice Game</title> <link rel="stylesheet" type="text/css" href="demo.css"> </head> <body> <div class="row" align="center"> <div class="col-4"> <h3>Your Dice</h3> <img src="images/d1.png" width="100" height="100" alt="roll: 1" id="mydice1"> <img src="images/d1.png" width="100" height="100"...
Write a program that takes two numbers from the Java console representing, respectively, an investment and...
Write a program that takes two numbers from the Java console representing, respectively, an investment and an interest rate (you will expect the user to enter a number such as .065 for the interest rate, representing a 6.5% interest rate). Your program should calculate and output (in $ notation) the future value of the investment in 5, 10, and 20 years using the following formula: future value = investment * (1 + interest rate)year We will assume that the interest...
So I would like to multiply a first digit by 2. I have to randomize either...
So I would like to multiply a first digit by 2. I have to randomize either 51-55 but multiply that very first digit by 2 whichever the number may come out to be. I also need to keep the string. FOR EXMAPLE: Code generates 51, multiply 5 * 2 to get 10 1 or if it generates 54, multiply 5 * 2 to get 10 4 the 1 and the 4 always stay the same, only the 5 is getting...
Create a program that determines ice cream size based on price How much would you like...
Create a program that determines ice cream size based on price How much would you like to pay for an ice cream? Use the input function to ask this question If the answer to question 1 is less than 2, print "Small ice cream" If the answer to question 1 is less than 4 and greater than 2, print "Medium ice cream" If the answer to question 1 is greater than or equal 4, print "Large ice cream"
Kyle would like to test if the vacancy rate for “warehouse” stores is more than 8%....
Kyle would like to test if the vacancy rate for “warehouse” stores is more than 8%. The correct hypothesis statement to test for this vacancy rate would be___________________ A) ?0:? ≤ 0.08; ?1:? > 0.08 B) ?0:? = 0.08; ?1:? ≠ 0.08 C) ?0:? ≤ 0.08; ?1:? ≠ 0.08 D) ?0:? < 0.08; ?1:? > 0.08 please I need help with the answer and explanation