2.99 See Answer

Question: Write a program that prompts the user

Write a program that prompts the user to enter an integer that represents an array size. Java generates a NumberFormatException if the user attempts to enter a noninteger value using nextInt(). Handle this exception by displaying an appropriate error message. If the size entered is an integer, create an array of type double using the integer entered as the size. Java generates a NegativeArraySizeException if you attempt to create an array with a negative size; handle this exception by setting the array size to a default value of five. If the array is created successfully, use exception-handling techniques to ensure that each entered array value is a double. Then calculate each element’s distance from the average. Save the file as DistanceFromAverageWithExceptionHandling.java.


See Answer