/ *
Operator: Logical Operator
! & && | || ^
Description:
1. The operation of the logical operator is a boolean variable
* /
Operator: Logical Operator
! & && | || ^
Description:
1. The operation of the logical operator is a boolean variable
* /
LogicTest class
{
public static void main (String [] args)
{
// & distinguish the &&
1 similarities @: & same calculation result &&
@ 2 point the same: when the symbol on the left is true both of which can perform symbol arithmetic right
@ differences: when the symbol on the left is false & proceed calculation operation && right symbol is no longer performed to the right of the symbol of the
Boolean B1 = to true;
B1 = to false;
int num1 = 10;
iF (B1 & (num1 ++> 0 )) {
System.out.println ( "I am now in Beijing");
} the else {
System.out.println ( "I am now in Nanjing");
}
System.out.println ( "num1 =" + num1);
{
public static void main (String [] args)
{
// & distinguish the &&
1 similarities @: & same calculation result &&
@ 2 point the same: when the symbol on the left is true both of which can perform symbol arithmetic right
@ differences: when the symbol on the left is false & proceed calculation operation && right symbol is no longer performed to the right of the symbol of the
Boolean B1 = to true;
B1 = to false;
int num1 = 10;
iF (B1 & (num1 ++> 0 )) {
System.out.println ( "I am now in Beijing");
} the else {
System.out.println ( "I am now in Nanjing");
}
System.out.println ( "num1 =" + num1);
B2 = to true Boolean;
B2 = to false;
int num2 = 10;
IF (B2 && (num2 ++> 0)) {
System.out.println ( "I am now in Beijing");
} the else {
System.out.println ( "I Nanjing ");
}
System.out.println (" num2 = "+ num2);
B2 = to false;
int num2 = 10;
IF (B2 && (num2 ++> 0)) {
System.out.println ( "I am now in Beijing");
} the else {
System.out.println ( "I Nanjing ");
}
System.out.println (" num2 = "+ num2);
@ Distinguished: | and ||
. 1 @ similarities: | || same calculation result
@ 2 point the same: when the sign is left to the right of both false operation will perform symbol
@ 3 differs: when the symbol on the left is true | to continue operation right of the symbols || operation is not executed to the right of the symbol
// development recommended &&
boolean b3 = false;
b3 = to true;
int num3 = 10;
IF (b3 | (num3 ++> 0 )) {
System.out.println ( "I am now in Beijing");
} the else {
System.out.println ( "I am now in Nanjing");
}
System.out.println ( "num3 =" + num3);
. 1 @ similarities: | || same calculation result
@ 2 point the same: when the sign is left to the right of both false operation will perform symbol
@ 3 differs: when the symbol on the left is true | to continue operation right of the symbols || operation is not executed to the right of the symbol
// development recommended &&
boolean b3 = false;
b3 = to true;
int num3 = 10;
IF (b3 | (num3 ++> 0 )) {
System.out.println ( "I am now in Beijing");
} the else {
System.out.println ( "I am now in Nanjing");
}
System.out.println ( "num3 =" + num3);
b4 = false boolean;
b4 = to true;
int Num4 = 10;
IF (b4 || (Num4 ++> 0)) {
System.out.println ( "I am now in Beijing");
} the else {
System.out.println ( " I am now in Nanjing ");
}
System.out.println (" Num4 = "+ Num4);
b4 = to true;
int Num4 = 10;
IF (b4 || (Num4 ++> 0)) {
System.out.println ( "I am now in Beijing");
} the else {
System.out.println ( " I am now in Nanjing ");
}
System.out.println (" Num4 = "+ Num4);
}
}
}