Java Fundamentals (Chapter four)

Source: Internet
Author: User

Java Fundamentals (Chapter four)

The syntax of a switch structure (switching statement)

switch (expression) {-------[dream1] type is int, char

CASE constant 1:---------[dream2]case structure can have multiple

Statement Block 1

break;---------[DREAM3] program jumps out of the switch structure

Case constant N: The value of the---------[DREAM4] constant cannot be the same

Statement block N

Break

Default: Same as else in----------[DREAM5] and if structures

Statement block

Break

}

Second, switch structure use occasions: int \char 2 types of equivalence judgment to use

Iii. the similarities and differences between switch structure and if structure

Same point: equal judgment can be achieved

Different points:

L syntax is different

L use different occasions.

n if structure, focusing on range judgment

N-switch structure, focusing on equivalence judgments, types can only be int, char type

L Efficiency

N in the equivalence judgment, the switch structure efficiency is higher than the IF structure

Iv. exception handling--hasnextint ();

Determines whether an integer

if (Input.hasnextint ()) {//Boolean type

code block

}

Java Fundamentals (Chapter four)

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.