Switch statements: Test a variable’s value with a list of values defined by us, where an appropriate match is found. The corresponding block of statements is executed and the structure is terminated.
- Syntax: –
- switch(expression)
- {
- case value-1: statements;
- break;
- case value-2: statements;
- break;
- case value-3: statements;
- break;
- [default : statement;]
- }
| /*A small demo on switch control structures*/
class App6{
} |
- output:
- \>javac App6.java
- \>java App6
- Three
