Java operator operation rules: 1. Arithmetic operators; 2. Assignment operators; 3. Relational operators; 4. Logical operators; 5. Ternary operators; 6. Bit operators; 7 , string " " operation; 8. Data input. Java operators are a special class of symbols used to perform various mathematical and logical operations in Java programs.
The operating system for this tutorial: Windows 10 system, DELL G3 computer.
Java operators are a special type of symbols used to perform various mathematical and logical operations in Java programs. The following are the operation rules of Java operators:
1. Arithmetic operators:
: addition operation, which can also be used for string concatenation.
-: Subtraction operation.
*: Multiplication operation.
/: Division operation, note that the result is a floating point number (unless both operands are integers).
%: Modulo operation, returns the remainder of division.
, --: auto-increment and auto-decrement operators, used to increase or decrease the value of a variable.
2. Assignment operator:
=: The basic assignment operator assigns the value on the right to the variable on the left.
Compound assignment operators such as =, -=, *=, /=, %=, &=, ^=, and |= combine assignment with corresponding arithmetic or bitwise operators.
3. Relational operator:
==: Check whether two values are equal.
!=: Check whether two values are not equal.
>: Check whether the value on the left is greater than the value on the right.
<: Check whether the value on the left is less than the value on the right.
>=: Checks whether the value on the left is greater than or equal to the value on the right.
<=: Checks whether the value on the left is less than or equal to the value on the right.
4. Logical operators:
&& (logical AND): When both sides are true, the result is true.
|| (Logical OR): The result is true when at least one of both sides is true.
! (Logical NOT): used to invert logical values, that is, true becomes false and false becomes true.
5. Ternary operator:
condition ? value1 : value2: If condition is true, the result is value1, otherwise it is value2.
6. Bit operators:
& (bitwise AND): When the corresponding bits are all 1, the result is 1, otherwise it is 0.
|(Bitwise OR): When at least one of the corresponding bits is 1, the result is 1, otherwise it is 0.
^ (Bitwise XOR): When the corresponding bits are not 1 at the same time, the result is 1, otherwise it is 0.
~(Bitwise negation): Negate each bit.
<<(left shift): Shift the value on the left to the left by the specified number of digits on the right.
>> (Signed right shift): Shift the value on the left to the right by the number of digits specified on the right. In the case of sign extension, the highest bit on the left (sign bit) is copied to preserve the sign.
>>> (Unsigned right shift): Shift the value on the left to the right by the number of digits specified on the right. Regardless of whether the value on the left is signed or unsigned, the highest bit on the left (if present) will be filled with 0s.
7. String operations: When a string appears in the " " operation, this " " is a string connector, not an arithmetic operation. For example, "Aunero123" means concatenating the string "Aunero" and the number 123, rather than mathematical addition.
8. Data input: Use the Scanner class to read data from the console. For example:
import java.util.Scanner; // 导包动作必须出现在类定义的上方 Scanner sc = new Scanner(System.in); // 创建对象 Scannersc=newScanner(System.in); //只有sc是变量名可以变,其他都不允许改变 接收数据 inti=sc.nextInt(); //只有i是变量名可以变,其他都不允许改变。
The above is the detailed content of What are the operation rules of java operators?. For more information, please follow other related articles on the PHP Chinese website!