In programming, there are three basic techniques that can change the process control of a program:
- Call method;
- Select
- Cycle.
Here, we mainly talk about the choice statement.
The selection statements in Java are essentially the same as in C, including:
- If statement;
- If/else statement;
- Switch statement.
If statement:
1 if (Boolean expression) {2 // if the Boolean expression in parentheses after the If is true, the statement here is executed 3 }
If/else statement:
1 if (Boolean expression) {2 // executes the statement here when the Boolean expression is true for the if post-parenthesis; 3 }else{4 // Executes the statement here when the Boolean expression is false in parentheses after the IF. 5 }
Or
if(Boolean expression) {//executes the statement here when the Boolean expression is true for the if post-parenthesis;}Else if(Boolean expression) {//executes the statement here when the Boolean expression is false in parentheses after this else if;}Else if(Boolean expression) {//executes the statement here when the Boolean expression is false in parentheses after this else if;}Else if(Boolean expression) {//......}Else{ //The above conditions are not satisfied when the implementation;}
Switch statement:
The switch statement allows the variable to be tested for equality with multiple values, and the switch statement generally has the following format:
1 Switch(variable) {2 Casevalue 1:3 statement;4 Break;//options available5 Casevalue 1:6 statement;7 Break;//options available8 .9 .Ten . One . A . - . - CaseValue N: the statement; - Break;//options available - default://default Optional - statement; +// Break;//options available -}
At this point, the three selection statements for Java Process Control are complete.
JAVA Process Control Selection statement