[course03] 04 switch case(not in AP)
Base switch case
switch (expression) {
case constant-1:
statements-1
break;
case constant-2:
statements-2
break;
.
. // (more cases)
.
case constant-N:
statements-N
break;
default: // optional default case
statements-(N+1)
} // end of switch statement
//same as
if (expression == constant-1) { // but use .equals for String!!
statements-1
}
else if (expression == constant-2) {
statements-2
}
.
.
.
else if (expression == constant-N) {
statements-N
}
else {
statements-(N+1)
}example : menus
Enum in switch statements
Last updated