Home » JAVA Programming » Exceptions » Question
  1. What is the output of this program?
    public class Exec_Handling_Example 
    {
    public static void main(String args[])
    {
    try
    {
    int k, n;
    n = 5;
    for (k = -2; k < 2 ;++k)
    {
    n = (n / k);
    System.out.print(k);
    }
    }
    catch(ArithmeticException e)
    {
    System.out.print("0");
    }
    }
    }
    1. -1 0
    2. 0 -1
    3. 0
    4. 1
    5. None of these
Correct Option: A

For the 1st iteration -1 is displayed. The 2nd exception is caught in catch block and 0 is displayed.



Your comments will be displayed only after manual approval.