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);
}
}

```

Computer Science & Information Technology

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

Computer Science & Information Technology

Which of the following printers requires manual alignment?

A. Laser B. Dot matrix C. Inkjet D. Thermal

Computer Science & Information Technology