If selection structure:
Syntax: if (condition) {
Code Block 1
}
IF--ELSE selection Structure
Syntax: if (condition) {
Code Block 1
}else{
Code Block 2
}
Multiple if selection structure
Syntax: if (condition 1) {
Code Block 1
}else if (condition 2) {
Code Block 2
}else{
Code block 3
}
Nested IF selection structure
Grammar:
if (condition 1) {
if (condition 2) {
Code Block 1
}else{
Code Block 2
}
}else{
Code block 3
}
Three judgments about the IF condition
1. &&: Two conditions are true at the same time.
2. | | Or: Two conditions one (at least one) is true when the condition is established.
3. ! Non: Two conditions at least one condition is false when not established.
The generation of random numbers:
int random = (int) (Math.random () *10);//Generate random number (0~9)
Attention:
When using if ——— else or multiple if or nested if there are several if there are several else
Multiple if can have more than else if but must have an else end
Java Chapter III