OCA Java SE 8 Operators/Statements - OCA Mock Question Operator and Statement 8








Question

What is the output of the following code snippet?

     3: int count = 0; 
     4: ROW_LOOP: for(int row = 1; row <=3; row++) 
     5:   for(int col = 1; col <=2 ; col++) { 
     6:     if(row * col % 2 == 0) continue ROW_LOOP; 
     7:     count++; 
     8:   } 
     9: System.out.println(count); 
  1. 1
  2. 2
  3. 3
  4. 4
  5. 6
  6. The code will not compile because of line 6.




Answer



A.

Note

public class Main{
   public static void main(String[] argv){
         int count = 0; 
         ROW_LOOP: for(int row = 1; row <=3; row++) 
         for(int col = 1; col <=2 ; col++) { 
             if(row * col % 2 == 0) 
                 continue ROW_LOOP; 
             count++; //from  w w w. j  a v a  2 s .c  o  m
         } 
         System.out.println(count); 
   }
}