Java OCA OCP Practice Question 290

Question

Consider the following code:

1. outer: for (int i = 0; i < 2; i++) { 
2.   for (int j = 0; j < 3; j++) { 
3.     if (i == j) { 
4.       continue outer; 
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


D.

Note

Whenever i and j have the same value, the outer loop is continued before the output is generated.

Because the outer loop is the target of the continue statement, the whole of the inner loop is abandoned.

The only line to be output is that shown in option D.




PreviousNext

Related