95.6k views
5 votes
Write an application that throws and catches an ArithmeticException when you attempt to take the square root of a negative value. Prompt the user for an input value and try the Math.sqrt() method on it. The application either displays the square root or catches the thrown Exception and displays an appropriate message.

User Augusta
by
5.2k points

1 Answer

1 vote

Answer:

Sample output:

Enter the number: 25

The square root of 25 is: 5

Enter the number: -25

The square root of 25 is: Nan

Step-by-step explanation:

Here the code is given as follows,

Write an application that throws and catches an ArithmeticException when you attempt-example-1
Write an application that throws and catches an ArithmeticException when you attempt-example-2
User JBrooks
by
5.0k points