One, if condition statement
Example:
import Java.util.Scanner; Public classtest{ Public Static voidMain (string[] args) {Scannerinch=NewScanner (System.inch); System. out. println ("Please enter student's score:"); intnum =inch. Nextint (); if(num== -) {System. out. println ("Perfect! "); } Else if(num> -&& num< -) {System. out. println ("qualified! "); } Else if(num== -) {System. out. println ("just qualified! "); } Else{System. out. println ("not qualified"); } }}
The syntax of the IF statement is the same as the javascript,php usage
Multi-nesting support.
Second, switch multi-branch structure
Instance:
ImportJava.util.Scanner; Public classtest{ Public Static voidMain (string[] args) {Scanner in=NewScanner (system.in); System.out.println ("Please enter the rank of Fox Punch:"); intnum =In.nextint (); //switch only supports integer (int) or character type (char) Switch(num) { Case1: System.out.println ("As a martial arts leader!" "); Break;//Jump Case2: System.out.println ("As Wudang Masters!" "); Break; Case3: System.out.println ("As an Emei head!" "); Break; default://defaultSYSTEM.OUT.PRINTLN ("Eviction door! "); } }}
Third, logical operators
&& is "with", for example: I>1 && i<3, if I is greater than 1 and less than 3 returns True
|| Yes or, for example: i>1 | | I<3, if I is greater than 1, or less than 3 returns True
! Is "non", for example:!i>1, if I is less than 1 returns true
JAVA If conditional statement, switch Multi-branch structure, and logical operator