Java programming ideology _ 006 short circuit Phenomenon

Source: Internet
Author: User

Short-circuit phenomenon: Once the value of the entire expression can be clearly determined, it is not included in the remaining part of the calculation expression.

& Short Circuit exists. Once an expression is used to determine the value of the entire expression, the remaining part does not need to be calculated.

| No short circuit. In any case, all parts of the expression must be calculated.

Package COM. WZS. thread; public class test6 {public static void main (string [] ARGs) {Boolean b1 = test1 (0) & Test2 (3) & test3 (2); system. out. println (); Boolean b2 = test1 (5) | Test2 (1) | test3 (2);} static Boolean test1 (INT value) {system. out. println ("test1:" + value); system. out. println ("Result:" + (value <1); return value <1;} static Boolean Test2 (INT value) {system. out. println ("Test2:" + value); system. out. println ("Result:" + (value <2); return value <1;} static Boolean test3 (INT value) {system. out. println ("test3:" + value); system. out. println ("Result:" + (value <3); return value <1 ;}}

Output result:

 
Test1: 0 result: truetest2: 3 result: falsetest1: 5 result: falsetest2: 1 Result: truetest3: 2 result: True

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.