A. There are three logical operator logical operators, namely "non", "and", "or", with "!", "&&", "| | |", respectively. Said. which
- Non-op (!) Indicates negation, such as:!true equals false,!false equals True,!2 equals false,!0 equals True.
- and arithmetic (&&) before and after two conditions are true, returns True, otherwise false.
- Or Operation (| |) Before and after two conditions there is a true, return to False, all false.
public class data10{
public static void Main (string[] args) {
int a=10;
int b=21;
int c=10;
System.out.println ("Say A>b, right?") "+! (a>b));
System.out.println ("Think A>b and A<b, right?" "+ ((a>b) && (a<b)));
System.out.println ("Think A>b and A<b, right?" "+ ((a>=b) | | (a==b)));
System.out.println ("Think A>b and A=c, right?" "+ ((a<b) | | (a==c)));
}
}
Operation Result:
Say A>b, right? True
Think both A>b and A<b, right? False
Think both A>b and A<b, right? False
Think both A>b and A=c, right? True two. The bitwise operator bit operator is primarily for binary, and it includes: "and", "Non", "or", "XOR", respectively "&", "~", "| "," ^ ". which
- The bitwise of the two operands with the operation (&) is 1, the result is 1, otherwise the result is 0.
- The bitwise of the operand of the non-operation (~) is 0, the result is 1, and if 1, the result is 0.
- or Operation (|) As long as two operands have a bit of 1, the result is 1, or 0.
- The phase of the two operand of an XOR operation (^) has a simultaneous result of 0, and the result is 1.
public class data13{
public static void Main (string[] args) {
int a=129;
int b=128;
int x=15;
int y=2;
System.out.println ("A and B" with the result is: "+ (a&b));
System.out.println ("A and B" or the result is: "+ (a|b));
System.out.println ("X and y xor result is:" + (x^y));
}
}
Operation Result:
A and B with the result is: 128
A and B or the result is: 129
The result of X and Y xor is: 13
6.Java logical operators and bitwise operators