Arithmetic operators
plus : When manipulating numbers, characters, and strings, the result is different, when two characters are added to the ASCII table value, and when two strings are added together, the two strings are concatenated to form a new string.
Division sign : integer when using the division sign operation, the resulting result is still an integer (fractional part omitted), and an arithmetic exception is thrown when the integer is divided by 0.
Positive Infinity (Infinity): When the number of a positive floating-point type is divided by 0 o'clock, or if the positive integer is divided by 0.0;
Negative infinity (-infinity): When the number of a negative floating-point type is divided by 0 o'clock, or a negative integer divided by 0.0;
NaN (not a number): When 0.0 is divided by 0.0;
Modulus (for remainder): Modulus of the symbol is ignored, the positive or negative of the result depends on the modulus.
Note: Both infinity and Nan are double floating-point types, but all positive infinity is equal, and all negative infinity is equal, and Nan is never equal or equal to itself.
+ + and--Detailed:
can only manipulate variables and cannot manipulate constants.
+ +: Indicates that the current action variable is self-accumulating 1.
--: Represents the current action variable minus 1
Self-Increase: + +, increment operator, increase the value of the variable by 1, there are pre-and post-points, can only manipulate variables.
Decrement:---decrements the operator so that the value of the variable is reduced by 1, with pre-and post-set points, and only the variables can be manipulated.
Self-increment and decrement specific operations are the same, just one is plus 1, one is minus 1,
Now the single Speaker + +: Code result + + and ++result will add 1 to the value of the result variable. The only difference is that the predecessor (++result): Indicates that the result after results plus 1 is evaluated, followed by (result++): Indicates that the value before the result variable plus 1 (the original value) is evaluated. If you simply perform a simple incremental operation (write result++ or ++result only), choose either one.
int a1 = 5= a1 + 1; // 6 int temp = A1; int B1 = temp; // 6--------------------------int a1 = 5; int temp = A1; // 5a1 = A1 + 1; // 6 int B1 = temp; // 5
Assignment operators
Note that Java supports assigning values to multiple variables at the same time, like supporting declaring multiple variables at the same time, but is not recommended because of the effect of code readability.
plus equals:x += 5, which is equivalent to x = x + 5, but also includes implicit type conversions.
Public class hello{ publicstaticvoid main (string[] args) { int A, b, C; // Not recommended // Not recommended Short s = 5//s = s + 3; // compile error, requires a strong turn s + = 3; // compile OK, implicit type conversion }}
Comparison operators
comparison operator
Used to compare the relationship between two variables or constants, the result of the comparison operator is a Boolean type, and its action format is: boolean result = expression A comparison operator expression B;
= =: Equals, if the comparison is two operands are numeric types, even if their type is different, as long as the same value returns TRUE. Of course = = can also compare the reference data type, compare the address
Ternary operators
The ternary operator, which represents an expression with three elements involved, is also called a trinocular operator, and its semantics represent if-else.
Syntax format: X? Y:z,
where x is a Boolean expression, the value of X is computed first, and if the x result is true then the result of the entire trinocular expression is Y, otherwise it is Z. The type of the result of the trinocular operator is determined by Y and Z.
logical operators
Used to manipulate two Boolean variables or constants, and the resulting type is also a Boolean. The syntax format is: boolean result = expression A logical operator expression B;
&: Indicates and, if both operands A and B are true, the result is true, otherwise the result is false.
&&: Same as & results, with short-circuit effect, if the left operand A is false,result must be false, and does not run the operation of B.
|: Indicates that either A and B are false and result is false, as long as there is a or B is true, the result is true.
|| : and | The result is the same, with a short-circuit effect, if the left operand A is true,result must be true, and the operation of B is not run.
^: Judging whether A and B are different, the difference is true, and the same is false.
!: Inverse,!true The result is False,!fasle the result is true.
Bitwise operators
Bit operation is a unary and two-dollar operation of the bitwise or binary number of the bit-mode in the program design.
Boolean True and False, which uses a bit of 1 and a decimal at the bottom. True:1 false:0
Follow the rules:
&: Two numbers participating in the operation, if the value of the corresponding digit is 1, then the result value of this bit is 1, otherwise 0.
|: Two numbers participating in the operation as long as there is a 1 in the corresponding bit, the result is 1.
^: The two numbers participating in the operation correspond to the same bit and the result is 0, otherwise 1.
~: To change each bits "1" to "0" and "0" to "1".
<<: Moves the binary code of the operand to the left of the specified number of digits, and then adds the null after the left shift using "0".
>>: To move the binary code of the operand to the right of the specified number of digits, the null after the right shift uses the "sign bit" to supplement: if positive use "0" supplement, if negative use "1" supplement;
>>>: Moves the binary code of the operand to the right of the specified number of digits, and the empty space after the right shift is supplemented with "0".
Precedence of operator operations
Java Basic operators