Revise the program in number 9 above to throw a NegativeNumberException if the user enters a negative number.
What will be an ideal response?
```
import java.util.*;
public class GetNumbers2
{
public static void main(String args[]) throws InputMismatchException,
NegativeNumberException
{
Scanner stdin = new Scanner(System.in);
System.out.print("Enter the first non-negative number: ");
int firstNumber = stdin.nextInt();
if(firstNumber < 0)
throw new NegativeNumberException();
System.out.print("Enter the second non-negative number: ");
int secondNumber = stdin.nextInt();
if(secondNumber < 0)
throw new NegativeNumberException();
System.out.println("Your numbers are " + firstNumber + "and " +
secondNumber);
}
}
```
You might also like to view...
________ makes the database unreadable by encrypting the database
A) Password protect B) Make ACCDE C) Digital Signature D) Encryption
Which of the following printers requires manual alignment?
A. Laser B. Dot matrix C. Inkjet D. Thermal