Question: Write an application that prompts the user to enter an integer and displays its square root. Accept the users entry as a String using the

Write an application that prompts the user to enter an integer and displays its square root. Accept the user’s entry as a String using the next Line() method. Then try to use the Integer. parse Int() method to convert the String to an integer. If the conversion throws an Exception, display an error message, and set the number to 0. Then, if the entered number is less than 0, throw an ArithmeticException to a catch block that explains you cannot take the square root of a negative number. If the entered number is not less than 0, take the square root of the number using the Math. sqrt() method, and display the result. Save the file as SqrtException.java.

Step by Step Solution

3.44 Rating (163 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautil public class SqrtException public static voi... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!