You wrote an application named DistanceFromAverage that allows a user to enter up to 15 double values and then displays
You wrote an application named DistanceFromAverage that allows a user to enter up to 15 double values and then displays each entered value and its distance from the average.
Now, modify that program to first prompt the user to enter an integer that represents the array size. Java generates a NumberFormatException if you attempt to enter a noninteger value using nextInt(); handle this exception by displaying an appropriate error message. Create an array 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 before the program calculates each element’s distance from the average.
Save the file as DistanceFromAverageWithExceptionHandling.java.
This problem has been solved!
Step by Step Answer: