Chapter III:1. Select the first type of structure:if(condition) {//code block} The second type:if(condition) {//code block 1}Else{ //Code 2} Explanation: If the condition result is ture, then execute code block 1 Otherwise execute code block 2. The third type:if(condition 1) {//code block 1}Else if(condition 2) {//code block 2 }··· { ··· }Else{ //code block 3} Explanation: If the condition 1 result is true, then execute code block 1 if condition 1 is false, then the next condition is judged, repeat the above procedure in turn 。 Note: Determine if the strings are the same using Str1.equals (STR2) to determine if the numbers are the same NUM1==num2
Public class *** { Public Static voidMain (string[] args) {Scanner input =NewScanner (System.inch); System. out. println ("Please enter user name:"); String XY=Input.next (); System. out. println ("please lose the password:"); intls =Input.nextint (); if(Xy.equals ("Qing") && (ls==123) ) {System. out. println ("welcome, Greenie."); }Else{System. out. println ("Sorry, you're not green."); }
Java: Chapter III