1. Program flow control: Sequential structure, branch structure, loop structure, control loop structure.
Sequential structure: If there is no process control in the code, the program runs down one line at a line until the end of the program.
2. Judgment statement if statement
The format of the IF statement:
Way One:
if (expression) { method body}
Way two:
if (expression) { execute statement; }else{ execute statement;}
Way three:
if (expression) { executestatement;}elseif(execute statement) { execute statement;}Else{EXECUTE statement; }
3. SELECT statement, switch statement
Format:
Switch (expression) { case expression: execution statement; break; Case expression: execute statement ;break; Case expression: execute statement ;break; default : execute statement; break; // can write can not write;}
Case and default are not in order, first to execute first cases, there is no matching time to execute the default, the end of the switch statement of two situations, one is break, if there is no break, then a line of execution, until the end, If a match is performed, the subsequent code will be executed.
Example:
classSwitch { Public Static voidMain (string[] args) {intA =7, B =5; Switch(A-b) { Case 3://the possible values of the expression;{System. out. println ("33!"); } Break; Case 4: {System. out. println ("44!"); } Break; default://an option that does not execute executes the statement!System. out. println ("Other of"); } }}
The values in switch can be bye, char, short, int four basic data types, and their wrapper classes and enumerations, string is an object, not a basic data type.
4. Loop structure: Used to deal with repetitive execution, according to the value of judging conditions, determine the number of execution of the program paragraph, and this program we become the loop body.
The loops are: While,for,do......while.
While: You don't need to know how many loops are in advance, just the time it takes to get the data done.
Do......while: It's the same as above, but he will do it first, in judgment.
For need to know the number of cycles;
Format:while(condition) {EXECUTE statement}
Format of the Do......while
Do { execute statement;}while (condition);
While: Can not be executed, do......while: at least once.
Java Basics (2)