Home / Java Programming / Flow Control :: Discussion

Discussion :: Flow Control

  1. What will be the output of the program?

     for (int i = 0; i 4; i += 2)
     {    
         System.out.print(i + " ");
     } 
     System.out.println(i); /* Line 5 */ 
    

     

  2. A.

    0 2 4

    B.

    0 2 4 5

    C.

    0 1 2 3 4

    D.

    Compilation fails.

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    Compilation fails on the line 5 - System.out.println(i); as the variable i has only been declared within the for loop. It is not a recognised variable outside the code block of loop.


Be The First To Comment