I understand that Java switch case
are designed this way but why is this behavior in Java
int x = 1;
switch(x){
case 1: System.out.println(1);
case 2: System.out.println(2);
case 3: System.out.println(3);
default: System.out.println("default");
}
output : 1
2
3
default
My question is why case 2 and 3 are executed? I know I omitted break statement
but x
was never 2 or 3 but case 2
and case 3
still executes?