Logical operators include &&, ||, !, and their operands must be boolean data. Logical operators can be used to connect relational expressions.
Variables or expressions whose results are of type boolean can be formed into logical expressions through logical operators.
Example:
publicclassMain{publicstaticvoidmain(String[]args){booleana=true;booleanb=false;System.out.println(a&&b=+(a&&b));System.out.println(a||b=+(a||b) );System.out.println(!(a&&b)=+!(a&&b));}}
The running results are as follows:
a&&b=falsea||b=true!(a&&b)=true