What is the output?
int x = 2;
String r = "";
switch (x) {
case 1: r += "a";
case 2: r += "b";
case 3: r += "c"; break;
default: r += "d";
}
System.out.println(r);
- bc
- b
- bcd
- abc
Execution jumps to case 2 and falls through into case 3 because there is no break, then stops at the break before default.
Play Problem Solving ▸