Java Chapter III

Source: Internet
Author: User

If selection structure:

Syntax: if (condition) {

Code Block 1

        }

IF--ELSE selection Structure

Syntax: if (condition) {

Code Block 1

}else{

Code Block 2

}

Multiple if selection structure

Syntax: if (condition 1) {

Code Block 1

}else if (condition 2) {

Code Block 2

}else{

Code block 3

}

Nested IF selection structure

Grammar:

if (condition 1) {

if (condition 2) {

Code Block 1

}else{

Code Block 2

}

}else{

Code block 3

}

Three judgments about the IF condition

1. &&: Two conditions are true at the same time.

2. | | Or: Two conditions one (at least one) is true when the condition is established.

3. ! Non: Two conditions at least one condition is false when not established.

The generation of random numbers:

int random = (int) (Math.random () *10);//Generate random number (0~9)

Attention:

When using if ——— else or multiple if or nested if there are several if there are several else

Multiple if can have more than else if but must have an else end

Java Chapter III

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.