import java.util.*;
public class ArrayIndexOutOfBoundsException {
public static void main(String[] args) {
int[] array = new int[100];
//创建一个有 100 个存储空间的数组 for(int i = 0; i < array.length; i++) { //for 循环在数组的每个索引中存储随机整数 array[i] = (int) (Math.random ()*100); }
Scanner input = new Scanner(System.in);
System.out.println("Enter the index of the array: ");
//提示用户输入索引来查找
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.");
}
}
}