Menu
Topics Index
...
`

Exceptions2416


If you need explanation Read this topic

If you need Answer Take test on this topic

Exceptions2416
What will be the output of the following program?
public class Exceptions {
    public static void main(String[] args) {
        int Numerator = 20, numerator = 0;;
        int Denominator = 0, denominator = 20;
        try {
            System.out.println(Numerator / Denominator);
        } catch (ArithmeticException e) {
            System.out.println("Denominator should not be 0 incase of integer division");
        }
        try {
            System.out.println(numerator / denominator);
        } catch (ArithmeticException e) {
            System.out.println("numerator should not be 0 incase of integer division");
        }
    }
}

A. Denominator should not be 0 incase of integer division
numerator should not be 0 incase of integer division
B. 0
numerator should not be 0 incase of integer division
C. Denominator should not be 0 incase of integer division
0
D. Compilation Error or Runtime Error
Topic: Java Built In Exceptions Checked Exceptions, Unchecked Exceptions

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans : c
in 1 st print statement... Denominatr is equal to zero....here exception occur...so  exception is caught by catch block  ..
denominator should not be zero printed.
next print statement... denominator 20...here no exception is occur... so ans 0 printed

Posted by Ananda Kumar    2014-04-04 03:55:14


ans is c bcz
in d 1st print statement... 20/0=exception occurs & so exception is caught by catch block ..
denominator should not be zero printed.

next print statement.0/20=0 so  no exception is occur... so ans 0 printed

Posted by Pooja Singh    2014-04-04 07:40:49


Congratulations Pooja Singh. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-07 13:33:40


© meritcampus 2019

All Rights Reserved.

Open In App