Hi,
First you have to know that you can use compilation time constants in a case evaluation, now, I recomended to use a pencil and a piece of paper and write this:
Since x value is 2
switch(z)
{
case x:System.out.println("0"); case 2 print 0
case x-1:System.out.println("1");break; case 1 print 1 break;
default:System.out.println("def"); default def
case x-2:System.out.println("2"); case 0 print 2
}
So now is easier to match cases, remember, if you don't see the break, you fall throug the cases:
z=0, print 2
z=1, print 1
z=2, print 0 (no break) and print 1 (break).
So since z goes from 0 to 2 the output is (Your Case For loop from 0 to z<3):
2 1 0 1
if z would go from 0 to 3 the Output will be (For loop from 0 to z<=3)
2 1 0 1 def 2