Home / Java Programming / Flow Control :: Discussion

Discussion :: Flow Control

  1. What will be the output of the program?

     int x = 3; 
     int y = 1;
     if (x = y) /* Line 3 */
     {     
        System.out.println("x =" + x);
     } 

     

  2. A.

    x = 1

    B.

    x = 3

    C.

    Compilation fails.

    D.

    The code runs with no output.

    View Answer

    Workspace

    Answer : Option C

    Explanation :

    Line 3 uses an assignment as opposed to comparison. Because of this, the if statement receives an integer value instead of a boolean. And so the compilation fails.


Be The First To Comment