Hi,
Please read the code given below.
public class FlowControl1 {
final static short x = 2;
final static int y = 0;
public static void main(
String[] args) {
for(int z=0; z<4; z++){
switch(z){
case x: System.out.print("0 ");
case x-1: System.out.print("1 "); break;
default: System.out.print("def ");
case x-2: System.out.print("2 ");
}
}
}
}
Output is : 2 1 0 1 def 2
My question is when z = 2, at that time it will go to "case x" as x = 2, but it also goes to the condition "case x-1". I think it should not be. Because "case x-1" will result in 1 and z is not equals to 1.

But both code and output is correct. Can anybody please help me?
Thanks.
-Jahnvi