Create a main class named arrayprogram


Assignment:

Create a main class named ArrayProgram that generates an array of fifty integers, all ranging from 1 to 100. The program should then prompt the user to enter an array index so the number in the array at that index can be found, but the user might not enter an integer. That would throw an InputMismatchException. Take steps to scold the user and stop the program if this happens.

If the user does enter an integer, call a method named returnIndexValue to return the integer at the specified index in the array. This method will take the array and the desired index as arguments, but the index may be too big for the array. That would throw an ArrayIndexOutOfBoundsException. Deal with that possible scenario in returnIndexValue.

The main method should print the integer at the specified index if no exceptionsare thrown. Sample runs are shown below.

Run One
Enter index of array to display.
four
You must enter an integer for the index.
Program stopped.

Run Two

Enter index of array to display.
75
75 is too high.
Index must be 0-49.
Run Three
Enter index of array to display.
35
That index holds 26

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create a main class named arrayprogram
Reference No:- TGS01934101

Now Priced at $20 (50% Discount)

Recommended (99%)

Rated (4.3/5)