You wrote an application named DistanceFromAverage that allows a user to enter up to 15 double values and then displays

Question:

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!


Do you need an answer to a question different from the above? Ask your question!

Step by Step Answer:

Related Book For  answer-question

Java Programming

ISBN: 978-1337397070

9th edition

Authors: Joyce Farrell

Question Details
Chapter # 12
Section: Exercises
Problem: 4
View Solution
Create a free account to access the answer
Cannot find your solution?
Post a FREE question now and get an answer within minutes. * Average response time.
Question Posted: January 14, 2019 11:28:37