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

    public class selection_statement_Example
    {
    public static void main(String args[])
    {
    int num1 = 10;
    int num2 = 20;
    if ((num2 = 5) == num1)
    {
    System.out.print(num2);
    }
    else
    {
    System.out.print(++num2);
    }
    }
    }
    1. 5
    2. 4
    3. 6
    4. 7
    5. 5
Correct Option: C

num2 is initialised to 5. The conditional statement returns false and the else part gets executed.
output: 6



Your comments will be displayed only after manual approval.