Question: java. The output is 2 1 0 def 1 def 1. Can you explain me the following code? public class Switch2 { final static short

java. The output is 2 1 0 def 1 def 1. Can you explain me the following code?

public class Switch2 {

final static short x = 2;

public 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 ");

default:

System.out.print("def ");

case x - 1:

System.out.print("1 ");

break;

case x - 2:

System.out.print("2 ");

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!