Got this question on a quiz, but I don't understand the answer. This was on a smartphone app, so no instructor to ask about it.
int x = 0;
switch (x) {
case 1:
System.out.print(1);
case 0:
System.out.print(1);
case 2:
System.out.print(3);
}
The answer (according to quiz) is "13". I don't get it. X is initialized as "0". So when x is passed into the switch, it should go to case 0. Instructions under case 0 are to print "1". I assume this is what it is doing, but where the three? Should there be breaks in here? But, even without a break to send the flow outside of the switch, x (zero) should not fulfill the term "case 2", so printing "3" shouldn't execute. There's no default either, but that is more poor form than syntax error.
Any help appreciated. Thanks in advance, all!