import java.util.Scanner;
public class uncheckedException{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int size = scanner.nextInt();
try {
if (size < 0) {
throw new IllegalArgumentException("Array size cannot be negative.");
}
int[] arr = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = scanner.nextInt();
}
int index = scanner.nextInt();
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException("The specified index does not exist");
}
System.out.println("Element at index " + index + ": " + arr[index]);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
} catch (IndexOutOfBoundsException e) {
System.out.println(e.getMessage());
} finally {
scanner.close();
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: