Java Study Third if judgment

Source: Internet
Author: User

JAVA judgment

Word: if else otherwise

Single branch:

If (condition)

{

code block

}

If is a judgment statement. The code is formatted as above.

The inside of the If bracket is an expression. Executes a code block if the expression value is set. After executing The IF statement after the code.

If the IF condition is not true, then the code block is skipped to execute the IF statement code.

Example

Int a=10;

If (A==20)

{

a++;

System.out.println (a);

}

This is a simple if-judgment statement.

An If statement is called a single-branch judgment and can only perform if the IF condition is met.

Dual Branch:

If (condition)

{

code block

}

Else

{

code block

}

Interpretation: If the condition of the If is not true, then the code block within the else is executed.

subsequent code will continue to be executed after the else is executed.

Example :

String gender= "female ";

If (Gender.equals ("female "))

{

SYSTEM.OUT.PRINTLN ("yes"+gender);

}

Else

{

System.out.println ("Not a girl, a Boy");

}

This is a simple multi-branch judgment .

Two cases can be judged. One is for women, the other is not a female case.

Multi-Branch

A multi-branch is a nesting of If.

If (condition)

{

code block

}

else if (condition )

{

code block

}

else if (condition)

{

}

*********

The nested pattern is as follows. can satisfy a variety of conditions of judgment.

Example

int money=52;

if (money>=500)

{

System. out . println ("Buy Cadillac ");

}Else if(money>=100)

{

System. out . println ("buy passat ");

}Else if(money>=50)

{

System. out . println ("Buy Elantra ");

}Else if(money>=10)

{

System. out . println ("buy Austrian extension ");

}Else

{

System. out . println ("Buy Czech ");

}

Java Study Third if judgment

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.