Web-android Engineer first form logical operators in -3-6 Java

Source: Internet
Author: User

Source: http://www.imooc.com/code/1301

Logical operators are primarily used for logical operations. The logical operators commonly used in Java are shown in the following table:

We can understand logical operators from the perspective of "voting":

1, and : Ask everyone to vote for consent, to pass an issue

2, or : Just ask a person to vote for permission to pass an issue

3, non : Someone originally voted to agree, through the non-operator, you can make their votes invalid

4. XOR : There is only one person who can vote to approve the issue.

When using logical operators, we encounter a very interesting " short circuit " phenomenon.

For example: (One > both) && (one < three), if you can determine that the left one > The run result is false, then the system thinks there is no need to execute the one < three on the right.

Similarly, in (One > both) | | (One < three), you can determine that the left expression will run as true, then the system also thinks there is no need to do the one < three on the right.

Task

Assuming that a, B, C, D four people vote, they decide whether to vote, it is time for the logical operator "to". please fill in the code in the editor 7, 8, 9, line, add the program complete

Combined operation Result:

, I believe that can help you better understand the application of logical operators ~ ~

1  Public classHelloWorld {2      Public Static voidMain (string[] args) {3         BooleanA =true;//a agree4         Booleanb =false;//b against5         Booleanc =false;//C Objection6         BooleanD =true;//D Agree7     8     9     Ten      One      A     } -}

1  Public classHelloWorld {2      Public Static voidMain (string[] args) {3         BooleanA =true;//a agree4         Booleanb =false;//b against5         Booleanc =false;//C Objection6         BooleanD =true;//D Agree7System.out.println ((a && B) + "failed");8System.out.println ((a | | d) + "pass");9System.out.println ((!a) + "failed");TenSystem.out.println ((c ^ d) + "pass");  One     } A}

Web-android Engineer first form logical operators in -3-6 Java

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.