Java中 &
&在Java中表示两种运算符,逻辑与和按位与。
在boolean类型运算时使用逻辑与运算,在数值类型运算时使用会用数值的二进制数进行按位与运算。
逻辑运算符:与
true & true = true
true & false = false
false & true = false
false & false = false
位运算符:按位与
0 & 0 = 0
1 & 1 = 1
0 & 1 = 0
1 & 0 = 0
public class text1 {
public static void main(String[] args){
int a = 3;
int b = 4;
int c = 5;
System.out.println((a>b) && (a>c));//false^false=false 全为真才为真
System.out.println((a>b) && (a<c));//false^ture=false
System.out.println((a<b) && (a>c));//true^false=false
System.out.println((a<b) && (a<c));//true^turse=true
System.out.println((a>b) || (a>c));//false^false=false 全为假才为假
System.out.println((a>b) || (a<c));//false^ture=true
System.out.println((a<b) || (a>c));//true^false=true
System.out.println((a<b) || (a<c));//true^turse=true
}
}