Multiple choice technology programming languages

1) What will be the output of the following program?package chapters.chap02;public class Chap02 { public static void main(String[] args) { for (int i=0; i<5; i++){ switch (i){ case 0: System.out.println("0"); ++i; break; case -1: System.out.println("-1"); break; case 2: System.out.println("2"); i++; case 4: System.out.println("4"); break; } } }}

  1. The program will not stop and it will run recursively upon execution

  2. The program will output '0 2 5 5'.

  3. The program will output '0 2 4 4'.

  4. The program will output '02 4 5'.

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

Tracing the loop: i=0 prints "0", ++i makes i=1, break exits switch, loop increments i to 2. i=2 prints "2", i++ makes i=3, falls through to case 4 (no break), prints "4", break exits switch. Loop increments i=4 to 5. i=5 doesn't match any case, nothing prints. Loop increments i=5 to 6, loop condition i<5 fails. Output: "0 2 4 4".