0.2
switch StatementsHere is what a switch statement looks like:
switch ( expression )
{
case label1:
statementList1
break;
case label2:
statementList2
break;
case label3:
statementList3
break;
. . . other cases like the above
default:
defaultStatementList
}
Here is how it works:
switch statement.expression determines which case is selected.expression must evaluate to byte, short, char, or int primitive data,
a String, or a few other types not discussed further here.expression and the type of the labels must agree.label must be an integer literal (like 0, 23, or 'A'), a String literal (like "green"), but not
an expression or variable.statementList.statementList is usually followed with break;switch statement is executed, the following happens:
expression is evaluated.labels after each case are inspected one by one,
starting with the first.statementList execute.break statement is encountered.switch statement is complete (no further statements are executed.)expression, then
the default case is picked, and its statements execute.expression, and there is no
default case, no statements execute.
Could the type of the expression be a float or a double?