Menu
Question Index
...

What will be the output of the following program?

public class TestExceptions {
    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            try {
                int a[] = new int[i];
                a[2] = a[i - 1] / i * a[1] / 0;
            } catch (Exception e) {
                System.out.println(e);
            }
        }
    }
}


java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero
java.lang.ArrayIndexOutOfBoundsException: 0
java.lang.ArrayIndexOutOfBoundsException: 1
java.lang.ArrayIndexOutOfBoundsException: 2
java.lang.ArrayIndexOutOfBoundsException: -1
java.lang.ArrayIndexOutOfBoundsException: 1
java.lang.ArithmeticException: / by zero
Some other output or Compilation Error

Doubts

Problems

Topic: Difference Between Error and Exception in Java

Read this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App