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
I have a text file that looks like this: Hello a/m The letter "a" is a...
I have a text file that looks like this: Hello a/m The letter "a" is a command that is supposed to append the letter "m" that is followed by the slash to the end of the word "Hello" How would I write a Java program to read and scan the file, and when the letter "a" is found, it appends "m" to the phrase "Hello"? The output should print "Hellom"
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...
In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that...
In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that displays the following patterns separately, one after the other. You MUST use nested for loops to generate the patterns, like the example in the PowerPoint slides from this chapter. All asterisks (*) should be displayed by a single statement of the form Console.Write("*"); which causes the asterisks to display side by side. A statement of the form Console.WriteLine(); can be used to move to...
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
I have a project I'm working on where I must selelct a company to write a...
I have a project I'm working on where I must selelct a company to write a report on and eventually present to my class. The first requirement is that the company is publicly traded but not regulated. I would like to work on L brands who I have confirmed is publicly traded but I can't figure out how to see if they are not regulated. Please help! I have searched everywhere
Java -How do I check if a number is valid without looping or any iterative processes?...
Java -How do I check if a number is valid without looping or any iterative processes? So I have a program that prompts the user to enter a number 1-5. (can include 1 and 5). It is to keep prompting the user until they enter a valid number. It's easy to do this with a while loop but for this assignment we are not supposed to use any type of loops or iterative processes. I am not good at recursion...
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"...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT