Java逻辑运算符如何运用

时间:2026-02-16 21:27:43

1、赋值运算符是为变量指定具体值的符号,顺序是从左到右。

Java逻辑运算符如何运用

2、下面说明短路与“&&”的运用

首先我们输入以下代码:

public class Test {

public static void main(String[] args) {

boolean a = true;

boolean b = false;

System.out.println("a && b:"+(a&&b));

  }

}

会看到输出结果:a && b:false

Java逻辑运算符如何运用

3、下面说明短路或“||”的运用

首先我随肤率们输入以下代码:

public class Test {

public static void main(String[] args) {

boolean a = true;

boolean b = false;

System.out.println("a || b:"+(a||b));

}

}

会看到输出结果:a || b:true

Java逻辑运算符如何运用

4、下面说明非“!”的运用

首先我们输入以下代码:

public class Test {

public static void main(String[] args) {

boolean a = true;

System.out.println("!a :"+(!a));

}

}

会看到输出结果:!a :false

Java逻辑运算符如何运用

5、下面说明或“&”的运用

首先我们输入以下代码:

public class Test {

public static void main(String[] args) {

boolean a = true;

boolean b = false;

System.out.println("英搁a & b :"+(a&b));

}

}

会看到输出结果:a & b :false

Java逻辑运算符如何运用

6、下面说明或“|”的运用

首先我们输入以下代码:

public class Test {

public static void main(String[] args) {

boolean a = true;

boolean b = false;

System.out.println("a | b :"+(a|b));

}

}

会看到输出结果:罩睡a | b :true

Java逻辑运算符如何运用

7、下面说明异或“^”的运用

首先我们输入以下代码:

public class Test {

public static void main(String[] args) {

boolean a = true;

boolean b = false;

System.out.println("a ^ b :"+(a^b));

}

}

会看到输出结果:a ^ b :true

Java逻辑运算符如何运用

© 2026 一点知道
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com