Two choices of Java architecture

Source: Internet
Author: User

Select structure: If structure: structure:
if () {:                      //Function Statement             }else if () {                      //Function Statement             }else if () {                      //Function Statement             }else{//Other case not established after execution                      /function statement             }

Characteristics:

1.if structure Independent write-off, with no effect on each other in order to judge and execute sequentially

2. If chain structure, if is mutually exclusive, when one of them executes, the condition is judged successfully, the IF structure ends

Precautions:

If the struct is not written, it will only control whether the first sentence of the IF structure is executed

Switch structure: structure notation:
switch (value variable expression) {//value, must be a Java-defined type case                                   value: function statement;                                   Case value: function statement; break;                                   Case value: function statement; break;                                   .......                                   Case value: function statement; break;                                   Default: function statement; break;}

Execution process:

According to the value of the parentheses after the switch, in the switch structure, determine whether the value followed by the case is matched with the value in parentheses, if matching, execute the function statement after the corresponding value of the box, the function statement is completed, a break is encountered, the selection structure ends, default: If there is no match after all case values are compared to the values passed in, the function statement following the default will be executed

Precautions:

1. Default can not be written

2. The order can be casually written: But it is recommended to follow the order

3. After matching the first case, execute the function statement, and before encountering the first break, all case invalidation

4. Generally written in the last condition, can not write break

5. Default: If written in front, it is best to write a break

Variable support type in switch ():

Java5 before: byte short char int

JAVA5 Support: Enum enumeration

JAVA7 Support: String type

Two choices of Java architecture

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.