标签:info 简单 void 逻辑 gic stat class int static
Hello!大家好,我是浩宇大熊猫~
加油~充实每一天~
java里面的逻辑运算符有与(&)、或(|)、异或(^)、非(!)
其实这些初高中数学课都学过哈,很简单~
public class Logic {
public static void main(String args[])
{
int a = 10;
int b = 20;
int c = 30;
//& 与
System.out.println((a>b)&(a>c));
//false&false = false
System.out.println((a<b)&(a>c));
//true&false = false
System.out.println((a>b)&(a<c));
//false&true = false
System.out.println((a<b)&(a<c));
//true&true = true
System.out.println("----------");
//| 或
System.out.println((a>b)|(a>c));
//false|false = false
System.out.println((a<b)|(a>c));
//true|false = true
System.out.println((a>b)|(a<c));
//false|true = true
System.out.println((a<b)|(a<c));
//true|true = true
System.out.println("----------");
//^ 异或
System.out.println((a>b)^(a>c));
//false^false = false
System.out.println((a<b)^(a>c));
//true^false = true
System.out.println((a>b)^(a<c));
//false^true = true
System.out.println((a<b)^(a<c));
//true^true = true
System.out.println("----------");
//! 非
System.out.println(!(a>b)&!(a>c));
//!false&!false = true
System.out.println(!(a<b)&!(a>c));
//!true&!false = false
System.out.println(!(a>b)&!(a<c));
//!false&!true = false
System.out.println(!(a<b)&!(a<c));
//!true&!true = false
System.out.println("----------");
}
}
结果如下~
前面两个应该都很简单,异或我一解释,大家应该都能明白。 异或也就是两个都是一样的就为false,若不一样则为true。 非就是否定啦~
标签:info 简单 void 逻辑 gic stat class int static
原文地址:https://www.cnblogs.com/BOSSH/p/12186637.html