In a Java program, you've arrays of integers and you want to fetch an element from an index. Given a scenario where you might attempt to access an index that is not within the array size (which would traditionally produce an error), fill the blanks in the provided code to handle this situation gracefully, and avoid the program from terminating abruptly. The message 'Array Index is Out Of Bounds' should be printed when such an event occurs.
Exception handling
Handling array index out of bounds exception
Report a typo
Fill in the gaps with the relevant elements
public class Main {
public static void main(String[] args) {
{
int[] arr = new int[5];
System.out.println(arr[7]);
} ( e) {
System.out.println("Array Index is Out Of Bounds");
}
}
}Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.