Chapter III Selection Structure
I. Common logical operators
1.&& and the meaning condition 1&& condition two need to satisfy two or more conditions simultaneously
2.| | Or or the meaning of the condition 1&& condition two, as long as one of the conditions can be satisfied
3.! Non -! Condition 1 The condition is true, the result is false, the condition is false, the result is true
Two. Four If structures
1. Single-Branch if structure
Declaring a variable
int i=10;
if (i>=5) {//condition conforms to continue execution of the statement in curly braces, otherwise jumps out of the loop
System.out.print ("Meet the Conditions");
}
2. Dual-branch if structure
if (i>=5) {
System.out.println ("Meet the Conditions");
}else{
SYSTEM.OUT.PRINTLN ("Non-conforming to conditions");
}
3. Multiple If structures
int i=100;
if (i>90) {//condition in sequence until the condition conforms to
System.out.println ("excellent");
}else if (i>80) {
System.out.println ("good");
}else if (i>60) {
SYSTEM.OUT.PRINTLN ("qualified");
}else{
SYSTEM.OUT.PRINTLN ("fail");
}
4. Nested IF structure
int i=10;
Char= ' Women ';
String gender= "female";
if (Gender.equals ("female")) {//If a first-tier condition is met, the first statement is executed and the second level is compared, otherwise the else in the first layer is executed
System.out.println ("Enter the women's group");
if (i>=10) {//If the second layer condition is met, proceed to the next statement, otherwise execute the else in the second layer
System.out.println ("Enter the women's group Finals");
}else{
System.out.println ("elimination");
}
}else{
System.out.println ("Into the men's group");
if (i>=12) {
System.out.println ("Enter the Finals");
}else{
System.out.println ("elimination");
}
}
First~~ Blog (Java chapter III)