import java.util.Scanner; public class ArrayAccessExample { public static void main(String[] args) { int[] array = {1, 2, 3, 4}; Scanner scanner = new Scanner(System.in); System.out.print("Enter an index: "); int index = scanner.nextInt(); try { System.out.println("Element at index " + index + " is " + array[index]); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Index out of bounds."); } } }