Question: Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array
Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. Out of Bounds) and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle invalid inputs, write two versions of your program: one that uses exception handling, and one that uses defensive programming. Assume a user will always enter numbers.
//bold characters are inputs
Sample:
Enter an index: 77
Out of Bound. Try again: 98
Out of Bound. Try again: 43
The element is 4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
