- "^" Bitwise logical operators
Class YSF {
public static void Main (string[] args) {
System.out.println (5 ^ 10 ^ 10);
System.out.println (5 ^ 10 ^ 5);
"^" Features: one data to another data bit XOR or two times, the number itself is unchanged
}
}
- Need to define third-party variables
Class YSF {
public static void Main (string[] args) {
int x = 10;
int y = 5;
int temp;
temp = x;
x = y;
y = temp;
System.out.println ("x =" + x + ", y =" + y ");
Define third-party variables, variable swaps
}
}
- No third-party variables required
Class YSF {
public static void Main (string[] args) {
int x = 10;
int y = 5;
x = x + y; 10 + 5 = 15
y = x-y; 15-5 = 10
x = XY; 15-10 = 5
System.out.println ("x =" + x + ", y =" + y ");
There is no need to define a third-party variable, there is a disadvantage, it is possible to exceed the value range of int
}
}
- You do not need to define a third-party variable by ^
Class YSF {
public static void Main (string[] args) {
int x = 10;
int y = 5;
x = x ^ y; 10 ^ 5
y = x ^ y; Ten ^ 5 y = 10
x = x ^ y; Ten ^ 5 ^ ten x=5
System.out.println ("x =" + x + ", y =" + y ");
Left x y x right all x ^ y
}
}
Java_ Study the next day (v) [Characteristics of bitwise XOR OR operator]