This article brings you a detailed introduction to the basic operators and logic control of Java (with examples). It has certain reference value. Friends in need can refer to it. Hope it helps.
Operators and logic control
Operators
Operators in java can be divided into the following types:
Operators
Relational operators
Bitwise operators
Logical operator
Assignment operator
Ternary operator
Operator | Description |
---|---|
Addition | |
- | Subtraction |
* | Multiplication |
/ | Division |
Remainder (modulo) | |
Auto-increment | |
Auto-decrement |
Description | |
---|---|
Check if the values of the two operands are equal, if so the condition is true | |
Check if the values of the two operands are equal, if the values are not equal then the condition is true | |
Check if the value of the left operand is greater than the right The value of the operand, if so then the condition is true | |
Check whether the value of the left operand is less than the value of the right operand, if so then the condition is True | |
Checks whether the value of the left operand is greater than or equal to the value of the right operand, if so then the condition is true | |
Check whether the value of the left operand is less than or equal to the value of the right operand, if so then the condition is true |
Description | ||
---|---|---|
And, if the corresponding bits are all 1, the result is 1, otherwise it is 0 | ||
Or, if the corresponding bits are all 0, the result is 0, otherwise it is 1 | ||
XOR, if the corresponding bit values are the same, the result is 0, otherwise it is 1 | ||
Negation, the bitwise negation operator flips each bit of the operand, that is, 0 becomes 1, and 1 becomes 0 | ||
Bitwise left shift operator. The left operand is shifted left by the number of digits specified by the right operand | ||
Bitwise right shift operation symbol. Shift the left operand bitwise right by the number of digits specified by the right operand | ||
##\ | \||||||||||||||||||||||||||||||||||||||
Logical OR. If either of the two operands is true, the condition is true | Logical negation. Used to invert the logical state of the operand. If the condition is true, the logical NOT operator will give false | |||||||||||||||||||||||||||||||||||||
The order of logical judgment is from left to right. When making logical judgments, there are ordinary AND (&), ordinary OR (|) and short-circuit AND (&&), short-circuit OR (||). Their differences are: 使用普通与、或操作时,所有的判断条件都会执行; 使用短路与运算时,只要有一个判断返回了false,后续的判断就不再执行。 使用短路或操作时,只要有一个判断返回了true,后学的判断就不再执行。 Copy after login Assignment operation
|
The above is the detailed content of Detailed introduction to Java basic operators and logic control (with examples). For more information, please follow other related articles on the PHP Chinese website!