Java OCA OCP Practice Question 282

Question

Consider the following code:

1. for (int i = 0; i < 2; i++) { 
2.   for (int j = 0; j < 3; j++) { 
3.     if (i == j) { 
4.       continue; 
5.     } 
6.     System.out.println("i = " + i + " j = " + j); 
7.   } 
8. } 

Which lines would be part of the output? (Choose all that apply.)

  • A. i = 0 j = 0
  • B. i = 0 j = 1
  • C. i = 0 j = 2
  • D. i = 1 j = 0
  • E. i = 1 j = 1
  • F. i = 1 j = 2


B, C, D, F.

Note

The loops iterate i from 0 to 1 and j from 0 to 2.

The inner loop executes a continue statement whenever the values of i and j are the same.

Because the output is generated inside the inner loop, after the continue statement, no output is generated when the values are the same.

The outputs suggested by options A and E are skipped.




PreviousNext

Related