逻辑运算符:&、&&、|、||
& 与 && :
&:左边无论是ture 还是 flase,右边也需进行运算。
&&:当左边为flase时,右边就不需进行运算,当为ture,则需运算右边。
public static void main(String[] args){
int x = 0;
int y = 10;
//*****if(x++ == 1 && ++y == 11){ // 该输出值为:x: 1 y : 10
System.out.println("x:"+x+"y:"+y);
}else{
System.out.println("x:"+x+"y:"+y);
}
}
}
| 与 ||:
|:左边无论是ture 还是 flase,右边也需进行运算。
||:当左边为ture时,右边就不需进行运算,当为flase,则需运算右边。
public static void main(String[] args){
int x = 0;
int y = 10;
//*****if(x++ == 0 || ++y == 11){ // 该输出值为:x: 1 y : 10
System.out.println("x:"+x+"y:"+y);
}else{
System.out.println("x:"+x+"y:"+y);
}
}
}