1. Java process structure: sequential structure, selection structure (branch structure), loop structure
2, select the structure: If statement, switch statement.
if (condition) { ... } Else { ... }
Switch (X) { Case 1: ... Break ; Case 2: //x==2 and x==3 when the same statement is executed 3: ... Break ; default : ... Break ; }
3, get keyboard input content:
① Importing package: Import Java.util.Scanner; or java.util.*;
② Create Scanner object: Scanner sc=new Scanner (system.in);
③ get user input: int a=sc.nextint ();
Double b=sc.nextdouble ();
String S=sc.next (); or String s=sc.nextline ();
4. String comparison:
= = Compare addresses
Equals Method Comparison Value
Note: When using the Equals method, it is best to write the constants in front, such as
"Male". Equals (gender). If you use Gender.equals ("male"), if you gender=null, the program throws an exception. Tring S=sc.next (); or String s=sc.nextline ();
5. Connection of strings:
Connection symbol: +
Attention:
System.out.println (3.0+2+ "3.0");//output Result: 5.03.0
SYSTEM.OUT.PRINTLN ("3.0" +2+3.0);//output Result: 3.023.0
SYSTEM.OUT.PRINTLN ("3.0" +2*3.0);//output Result: 3.06.0
System.out.println (3.0-2+ "3.0");//output Result: 1.03.0
SYSTEM.OUT.PRINTLN ("3.0" +2.5-1.0);//Compilation error
Learn Java from zero (3)--Process Control