Java selection Structure------------if statement switch statement

Source: Internet
Author: User
Tags case statement

Java selection structure (if statement switch statement)

1.IF Selection Structure:
①if (Boolean expression) {
If the Boolean expression is true, the statement executed
}
* If there is only one statement after the IF statement, the curly brace of the IF statement may not

②if (Boolean expression) {
If the Boolean expression is true, execute the
}else{
Executes if the Boolean expression is False
}
* An else can only follow a related If,else statement cannot appear alone

③if (Boolean expression) {
If the Boolean expression is true, execute the
}else if (Boolean expression) {
Executes if the Boolean expression is False
}else if (Boolean expression) {
Executes if the Boolean expression is False
. . . . . .

}else{
If all of the above are false, execute the
}
* Above a if/else block is executed, the control flow will then jump out of the if/else structure,
* and subsequent Boolean expressions are not detected

Case:



2..SWITCH selection Structure
Switch (variable) {
Case value:--->case followed by a colon, the data type of the value is the same as the variable, must be constant or literal
Statement
break;----> can not write, if not write, will continue to execute the next case;
Case Value:
Statement
break;----> can not write, if not write, will continue to execute the next case;
Case Value:
Can have a lot of case statements;
Break,----> If written, will jump out of the switch statement directly to the next line of the switch statement
Default:---> can write not write
Statement----> All case does not match, it executes
}
The *switch statement allows a variable to be tested for equality with multiple values, not a larger, smaller comparison, each value being
* A case statement invocation and detection.

Case:

Java selection Structure------------if statement switch statement

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.