the code block after each case can have multiple statements that can have a set of statements and do not need to be enclosed in "{}" .
Note: in JDK1.6 and previous versions, theswitch selection structure must have an integer variable or a character variable, but in JDK1.7, the condition of the switch selection structure can also be used The String type.
Select a structure summary:
Java provides two of the most important selection structures, they are the if selection structure and the switch selection structure.
(i) the if selection structure in Java, including the following form.
1. Basic If selection structure
if ( condition ) {
code block
}
2.if-else selection structure
if ( condition ) {
code block 1
}else{
code block 2
}
3. Multiple If selection structure
if ( condition 1) {
code block 1
}else if ( condition 2) {
code block 2
}else{
code block 3
}
4. Nested If selection structure
if ( condition 1) {
if ( condition 2) {
code block 1
}else{
code block 2
}
}else{
if ( condition 3) {
code block 3
}else{
code block 4
}
}
(ii) switch selection structure in Java
The Scanner object's Hasnextint () method is called to determine whether the characters entered by the user from the keyboard are legitimate.
S1/using Java to understand program logic/04-selection Structure (ii)