All cases of the switch will be printed
Strange, but in Java that’s how switch works.
In the following program, once numOfballs falls in the 1st case, all the rst cases will be visited regardless the condition.
public class App {
public static void main(String[] args) {
var numOfBalls = 1;
switch (numOfBalls) {
case 1: System.out.println("One ball");
case 2: System.out.println("Two balls");
case 3: System.out.println("Three balls");
case 4: System.out.println("Four balls");
case 5: System.out.println("Five balls");
}
}
}
Continue Reading
All cases of the switch will be printed