JAVA if Condition Statement, switch multi-branch structure, and logical operators, switch operators
I. if condition statements
Example:
Import java. util. role; public class Test {public static void main (String [] args) {role in = new role (System. in); System. out. println ("Enter the student's score:"); int num = in. nextInt (); if (num = 100) {System. out. println ("full score! ");} Else if (num> 60 & num <100) {System. out. println (" qualified! ");} Else if (num = 60) {System. out. println (" just qualified! ") ;}Else {System. out. println (" unqualified ");}}}
The syntax of the if statement is the same as that of javascript and php.
Multiple Nesting is supported.
Ii. switch multi-branch structure
Instance:
Import java. util. role; public class Test {public static void main (String [] args) {role in = new role (System. in); System. out. println ("Enter the ranking of Linghu Chong:"); int num = in. nextInt (); // switch only supports INTEGER (int) or character type (char) switch (num) {case 1: System. out. println ("as the martial arts leader! "); Break; // jump out of case 2: System. out. println (" head of Wudang! "); Break; case 3: System. out. println (" head of Emei! "); Break; default: // default System. out. println (" eviction! ");}}}
Iii. logical operators
& Is "and"-> For example: I> 1 & I <3. If I is greater than 1 and less than 3, true is returned.
| Yes "or"-> For example: I> 1 | I <3. If I is greater than 1 or less than 3, true is returned.
! Is "not"-> example :! I> 1. If I is less than 1, true is returned.