今日份代码:
public class MainMethod { public static void main(String[] args) { boolean flag = true; flag &= true; System.out.println("true &= true ==> " + flag); flag = true; flag &= false; System.out.println("true &= false ==> " + flag); flag = false; flag &= true; System.out.println("false &= true ==> " + flag); flag = false; flag &= false; System.out.println("false &= false ==> " + flag+" "); flag = true; flag |= true; System.out.println("true |= true ==> " + flag); flag = true; flag |= false; System.out.println("true |= false ==> " + flag); flag = false; flag |= true; System.out.println("false |= true ==> " + flag); flag = false; flag |= false; System.out.println("false |= false ==> " + flag+" "); System.out.println("^= 相同为假,不同为真"); flag = true; flag ^= true; System.out.println("true ^= true ==> " + flag); flag = true; flag ^= false; System.out.println("true ^= false ==> " + flag); flag = false; flag ^= true; System.out.println("false ^= true ==> " + flag); flag = false; flag ^= false; System.out.println("false ^= false ==> " + flag); } }
结果:
true &= true ==> true true &= false ==> false false &= true ==> false false &= false ==> false true |= true ==> true true |= false ==> true false |= true ==> true false |= false ==> false ^= 相同为假,不同为真 true ^= true ==> false true ^= false ==> true false ^= true ==> true false ^= false ==> false