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.