Question: Design and implement a Java class (name it OutOfBoundException) to determine and handle illegal array index values using IndexOutOfBoundsException class. The program defines an integer
Design and implement a Java class (name it OutOfBoundException) to determine and handle illegal array index values using IndexOutOfBoundsException class. The program defines an integer array of size 10 elements, populates the array with random integer numbers, then asks the user to enter an index value between 0 and 9 and print out the number stored in that location in the array. The program must include a try-and-catch exception handling block to detect out of bound index values. If an invalid index is detected, the program prompts the user to re-enter a valid index. The following are sample runs to illustrate required output formatting. Enter index value between 0 and 9: 3 The element at index 3 is 2029 Enter index value between 0 and 9: 23 Index out of bound, re-enter a valid index: 56 Index out of bound, re-enter a valid index: fr Index out of bound, re-enter a valid index: 1.4 Index out of bound, re-enter a valid index: 8 The element at index 8 is 5083
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
