Java OCA OCP Practice Question 1419

Question

What will be the output when the following program is run?

public class Main{ 
   public static void main (String args []){ 
      int i; /*from ww  w .j a v a  2s . c om*/
      int j; 
      for  (i = 0, j = 0; j < i; ++j, i++){ 
         System.out.println (i + " " + j); 
       } 
      System.out.println (i + " " + j); 
    } 
} 

Select 1 option

  • A. 0 0 will be printed twice.
  • B. 0 0 will be printed once.
  • C. It will keep on printing 0 0
  • D. It will not compile.
  • E. It will print 0 0 and then 0 1.


Correct Option is  : B

Note

++j and i++ do not matter in this case.

The loop will not execute even once since j is not less than i at the start of the loop.

The condition fails and the program will print 0 0 just once.




PreviousNext

Related