Question: java. The output is -- B B A -- B C. Can you explain me the code following? public class ForSwitch { final static short

java. The output is -- B B A -- B C. Can you explain me the code following?

public class ForSwitch {

final static short x = 2;

final static int y = 3;

public static void main(String [] args) {

for (int z = 0; z < 4; z++) {

switch (z) {

case x:

System.out.print("A ");

default:

System.out.print("-- ");

case x - 1:

System.out.print("B ");

break;

case y:

System.out.print("C ");

}

}

}

}

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!