Write an application that prompts the user to enter an integer and displays its square root. Accept

Question:

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.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Java Programming

ISBN: 9780357673423

10th Edition

Authors: Joyce Farrell

Question Posted: