Logical operators for Java Note 5 and differences between && and &

Source: Internet
Author: User

1 & Logic with : False if False.
| logical OR : true if True.
^ Logical XOR : The same is false, and the difference is true.
Example: Couple relationship. Male, female, male, female
The logical non : False is true, and false if not true.
Features: An even number does not change itself.

2
the difference between && and &? and | The difference?
A: The end result is the same.
The b:&& has a short circuit effect. The left side is false and the right side is not executed.

1 classOperatorDemo2 {2      Public Static voidMain (string[] args) {3         intA = 3;4         intb = 4;5         intc = 5;6         7         //&& Double and8System.out.println ((a > B) && (a > C));//false && false = False9System.out.println ((a > B) && (a < C));//false && true = FalseTenSystem.out.println ((a < b) && (a > C));//true && false = False OneSystem.out.println ((a < b) && (a < C));//true && true = True ASystem.out.println ("----------------"); -          -         intx = 3; the         inty = 4; -          -         //Boolean B1 = ((x + = = 3) & (y++ = = 4)); -         //Boolean B1 = ((x + = = 3) && (y++ = = 4)); +         //Boolean B1 = ((++x = = 3) & (y++ = = 4)); -         BooleanB1 = ((++x = = 3) && (y++ = = 4)); +System.out.println ("x:" +x); ASystem.out.println ("Y:" +y); at System.out.println (B1); -     } -}





Logical operators for Java Note 5 and differences between && and &

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.