Check the code: public class testorinfo {
Public static Boolean compareit (int I) {if (I> 10) {system. out. println ("in the (I> 10)"); Return true;} else {system. out. println ("in the (I <= 10)");} return false;} public static void main (string [] ARGs) {If (compareit (111) | compareit (2) {// note that system. out. println ("OK ");}}}
/* Print the output result as follows: In the (I> 10) OK ================, when the first condition compareit (111) is determined to be true, compareit (15) is not executed ). Because | or operation, when a condition is true, you can determine this or operation, that is, the entire judgment condition is true. So there is no output as expected: In the (I <= 10) in the (I> 10) OK is the same as & RMB, when the result on the left is falses, the result on the right is not determined, because it is enough to judge that the entire & Meta is false.
*/Finally try to replace & with & and replace | with | and then run the above program. You will see different results. After you re-modify the program and run the program as mentioned above, you will find & | in fact, it is flexible and reduces the execution of statements according to the actual situation, as we can see in the program results, we advocate using & and | when making judgments, because of its high efficiency. Although & and | can also be implemented. Another thing to remember is that & and | can also perform bitwise operations, so it seems that & and | assume multiple roles.