Home » JAVA Programming » Arrays » Question
  1. What is the output of this program?

    public class Result
    {
    public static void main(String args[])
    {
    int p , q = 2;
    p = 20;
    if (p != 20 && p / 0 == 0)
    {
    System.out.println(q);
    }
    else
    {
    System.out.println(++q);
    }
    }
    }
    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
Correct Option: C

Operator short circuit and, &&, skips evaluating right hand operand if left hand operand is false thus division by zero in if condition does not give an error.
output: 3



Your comments will be displayed only after manual approval.