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 would like to know how to implement the extended euclidean algorithm in Java which takes...
I would like to know how to implement the extended euclidean algorithm in Java which takes 2 integers, public int xgcd(int a, int b) and returns the multiplicative inverse of 'a' modulo 'b' and if the multiplicative inverse of 'a' does not exist it should return -1. I know to do it in a recursive manner but I need help with the non-recursive or iterative manner without using biginteger.math. Something like using the pseudocode would do. I would really appreciate...
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
i need to fix this java code. it not working on Repl.it website online compiler. error...
i need to fix this java code. it not working on Repl.it website online compiler. error -----------------------------------------------  javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -d . Main.java  java -classpath .:/run_dir/junit-4.12.jar:target/dependency/* Main Exception in thread "main" java.io.FileNotFoundException: C:\\Users\\Carter Collins\\Downloads\\input.txt (No such file or directory) at java.base/java.io.FileInputStream.open0(Native Method) at java.base/java.io.FileInputStream.open(FileInputStream.java:219) at java.base/java.io.FileInputStream.(FileInputStream.java:157) at java.base/java.util.Scanner.(Scanner.java:639) at Main.main(Main.java:18) exit status 1 ------------------------------------------------ codes:: import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner scan = new Scanner(System.in); Scanner sc...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT