Question: Use Java Recovering from a parseInt error Write a program that does the following: 1. Prompt the User for 10 integers. 2. Read each integer

Use Java

Recovering from a parseInt error

Write a program that does the following:

1. Prompt the User for 10 integers. 2. Read each integer as a string. DO NOT STORE THE INTEGERS IN AN ARRAY! 3. Use the parseInt method to convert each string as it is entered into an integer.

If the input is not valid (ie: not an integer) a NumberFormatException will be thrown when you try to convert it from string to integer. If this exception is thrown:

1. Print an appropriate error message letting the User know that the input is not an integer. 2. Recover from the error by allowing the loop to continue until all 10 numbers are entered and all are valid. Do not count the non-integer value when the exception is thrown.

DO NOT exit the loop if an invalid number is entered. Once the loop is started it must finish - the exception handling you incorporate should allow the program to recover from the exception and continue on to finish the loop.

Suggestion: Get the program to work for one integer first. Then add the loop and get it to work with the loop.

NOTE: 1. Declare all variables within the data declaration section. 2 Do not get input on the same line as a variable declaration. 3. Do not place an equation for computation on the same line as declaring a variable.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!