Difference between & amp; and & amp; in java, javascript

Source: Internet
Author: User

Java & difference, javascript

In java, both & and & belong to logical operators. They are true when both conditions are true. Otherwise, they are false.

In the program & Usage:

1 public static void main (String [] args) {2 int I = 3; 3 if (I ++> 5) & (I ++ <9 )) {4 System. out. println (I); 5 System. out. println ("congratulations, the conditional statement has been executed"); 6} 7 System. out. println (I); 8}

The result of this Code is: 5

That is to say, the logical operator actually will execute the first and second Judgment conditions twice, and the I self adds two times, and the result is: 5.

Public static void main (String [] args) {int I = 3; if (I ++> 5) & (I ++ <9) {System. out. println (I); System. out. println ("congratulations, the conditional statement has been executed");} System. out. println (I );}

The code execution result is: 4

That is to say, when the & logical operator only determines that the first condition is false, the result is: 4.

The differences between them are as follows:

&: When the first two conditions of the current judgment are false, the latter is not executed. The final conclusion is that the judgment is false.

&: Compare the judgment results of the front and back expressions. Therefore, I ++ is displayed, and the result is run twice.

 

Related Article

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.