import java.util.*;
public class ArrayIndexOutOfBoundsException {
public static void main(String[] args) {
int[] array = new int[100];
//creating array with 100 storage spaces for(int i = 0; i < array.length; i++) { //for loop to store random integers in each index of the array array[i] = (int) (Math.random()*100); }
Scanner input = new Scanner(System.in);
System.out.println("Enter the index of the array: ");
//prompting user to enter index to find
try {
int index = input.nextInt(); //declaring index variable to take on inputed value
System.out.println("The integer at index "+index+" is: "+array[index]); //printing the integer at the specified index
}
catch (ArrayIndexOutOfBoundsException ex) { //if user enters index value outside of 0-99, exception message will print
System.out.println("Out of bounds.");
}
}
}
ArrayIndexOutOfBoundsException. Which isn't an exception type, it's just the name of the class. What are you expecting to throw your custom class as an exception?