Java's judgment structure:
1, if (conditional expression) {
EXECUTE statement
};
2, if (conditional expression) {
EXECUTE statement
}else{
EXECUTE statement
}
3.
if (conditional expression) {
EXECUTE statement
}else if (conditional expression) {
EXECUTE statement
}
else{
EXECUTE statement
}
4. Nested IF...ELSE statements
if (conditional expression) {
EXECUTE Statement 1
if (conditional expression) {
EXECUTE Statement 2
}else{
EXECUTE Statement 3
}
}
Switch statement interval judgment selection
switch (expression) {
Case Value 1: Execute statement 1; Break//within the value of 1, execute 1
; Case Value 2: Execute statement 2; Break Within 2 of the value, execute 2
default: Execute statement 3; break;} Not within the value, perform 3 examples: score distinction: Greater than 90 is divided into excellent, 70 to 90 is good, more than 60 is passed; less than 60 is failing.
Attention:
1、这里switch和if用法类似一样,区别if除了能判断具体数值,还可以判断区间,而我们的switch判断区间很费劲。对于运算结果是boolean的if可以判断,但是switch不能判断。 2、在我们在具体数值之间进行判断,数值不多的情况我们可以用switch
Section II Java Process Control (judging structure + selection structure)