Multiple choice technology web technology

Given: 3. public class Wind { 4. public static void main(String[] args) { 5. foreach: 6. for(int j=0; j<5; j++) { 7. for(int k=0; k< 3; k++) { 8. System.out.print(" " + j); 9. if(j==3 && k==1) break foreach; 10. if(j==0 || j==2) break; 11. } 12. } 13. } 14. } What is the result?

  1. 0 1 2 3

  2. 1 1 1 3 3

  3. 0 1 1 1 2 3 3

  4. 1 1 1 3 3 4 4 4

  5. 0 1 1 1 2 3 3 4 4 4

  6. Compilation fails

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

When j=0, k=0: prints '0', then j==0 breaks inner loop. Next, j=1: inner loop runs for k=0, 1, 2, printing '1 1 1'. Next, j=2, k=0: prints '2', then j==2 breaks. Next, j=3, k=0: prints '3'. For k=1: prints '3', and j==3 &amp;&amp; k==1 triggers break foreach, terminating the outer loop. Output is ' 0 1 1 1 2 3 3'.