Java OCA OCP Practice Question 616

Question

Given the following code, which of these statements are true?

class Main{ // w ww  .j  a  va 2 s . co  m
   public static void main (String args []){ 
      int k = 0; 
      int m = 0; 
      for  ( int i = 0; i <= 3; i++){ 
         k++; 
         if  ( i == 2){ 
            // line 1 
          } 
         m++; 
       } 
      System .out.println ( k + ", " + m ); 
    } 
} 

Select 3 options

  • A. It will print 3, 2 when line 1 is replaced by break;
  • B. It will print 3, 2 when line 1 is replaced by continue.
  • C. It will print 4, 3 when line 1 is replaced by continue.
  • D. It will print 4, 4 when line 1 is replaced by i = m++;
  • E. It will print 3, 3 when line 1 is replaced by i = 4;


Correct Options are  : A C E

Note

This is a simple loop. All you need to do is execute each statement in your head.




PreviousNext

Related