Section II Java Process Control (judging structure + selection structure)

Source: Internet
Author: User

Java's judgment structure:

1, if (conditional expression) {

EXECUTE statement

};

2, if (conditional expression) {

EXECUTE statement

}else{

EXECUTE statement

}

3.

if (conditional expression) {

EXECUTE statement

}else if (conditional expression) {

EXECUTE statement

}

else{

EXECUTE statement

}

4. Nested IF...ELSE statements

if (conditional expression) {

EXECUTE Statement 1

if (conditional expression) {

EXECUTE Statement 2

}else{

EXECUTE Statement 3

}

}

Switch statement interval judgment selection

switch (expression) {

Case Value 1: Execute statement 1; Break//within the value of 1, execute 1

; Case Value 2: Execute statement 2;     Break Within 2 of the value, execute 2

default: Execute statement 3; break;} Not within the value, perform 3 examples: score distinction: Greater than 90 is divided into excellent, 70 to 90 is good, more than 60 is passed; less than 60 is failing.

Attention:
1、这里switch和if用法类似一样,区别if除了能判断具体数值,还可以判断区间,而我们的switch判断区间很费劲。对于运算结果是boolean的if可以判断,但是switch不能判断。 2、在我们在具体数值之间进行判断,数值不多的情况我们可以用switch

Section II Java Process Control (judging structure + selection structure)

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.