int value = 0;
switch (value) {
case 0:
// do something
break;
case 1:
// do something else
break;
default :
// something if anything not match
}
switch(x){
case(0): //if x == 0
//do some stuff
break;
//add more cases
default: //when x does not match any case
//do some stuff
break;
}
class Main {
public static void main(String[] args) {
int expression = 9;
switch(expression) {
case 2:
System.out.println("Small Size");
break;
case 3:
System.out.println("Large Size");
break;
// default case
default:
System.out.println("Unknown Size");
}
}
}
For details about Java Switch tutorial visit website:
https://www.allaboutjava.com/2021/07/java-switch-statements.html
switch (expression) {
case value1:
// code
break;
case value2:
// code
break;
...
...
default:
// default statements
}
switch(object.enum) {
case CONSULTOR:
tipoConsultor = "CO";
break;
case CONSULTOR_EN_LINEA:
tipoConsultor = "CL";
break;
case CONSULTOR_POR_PRODUCTO:
tipoConsultor = "CP";
break;
default:
break;
}
case 6:
System.out.println("Today is Saturday");
break;
case 7: