First~~ Blog (Java chapter III)

Source: Internet
Author: User
Tags logical operators

Chapter III Selection Structure


I. Common logical operators


1.&& and the meaning condition 1&& condition two need to satisfy two or more conditions simultaneously


2.| | Or or the meaning of the condition 1&& condition two, as long as one of the conditions can be satisfied


3.! Non -! Condition 1 The condition is true, the result is false, the condition is false, the result is true


Two. Four If structures
1. Single-Branch if structure
Declaring a variable
int i=10;

if (i>=5) {//condition conforms to continue execution of the statement in curly braces, otherwise jumps out of the loop
System.out.print ("Meet the Conditions");
}

2. Dual-branch if structure
if (i>=5) {
System.out.println ("Meet the Conditions");
}else{
SYSTEM.OUT.PRINTLN ("Non-conforming to conditions");
}

3. Multiple If structures

int i=100;

if (i>90) {//condition in sequence until the condition conforms to
System.out.println ("excellent");
}else if (i>80) {
System.out.println ("good");
}else if (i>60) {
SYSTEM.OUT.PRINTLN ("qualified");
}else{
SYSTEM.OUT.PRINTLN ("fail");
}

4. Nested IF structure

int i=10;

Char= ' Women ';

String gender= "female";
if (Gender.equals ("female")) {//If a first-tier condition is met, the first statement is executed and the second level is compared, otherwise the else in the first layer is executed
System.out.println ("Enter the women's group");
if (i>=10) {//If the second layer condition is met, proceed to the next statement, otherwise execute the else in the second layer
System.out.println ("Enter the women's group Finals");
}else{
System.out.println ("elimination");
}
}else{
System.out.println ("Into the men's group");
if (i>=12) {
System.out.println ("Enter the Finals");
}else{
System.out.println ("elimination");
}
}

First~~ Blog (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.