Reputation: 25
We have 137/42 == 0 && 137/0 == 42
I have to find the output of the following code in Java.
So 137/42 is 3 and now I have 3 ==0 && 137/0 ==42
First of all what does 3==0 result in ? Also since diving by zero results in an error how come we have 137/0==42?
and I know && means AND but what does that result in?
Upvotes: 0
Views: 273
Reputation: 393841
Since 3 == 0
is false
and the boolean AND (&&
) operator is short circuited, the right operand (137/0 ==42
) won't be evaluated when the first operand is false
, so the exception won't be thrown and the entire expression will be evaluated to false
.
Upvotes: 7