Home  >  Article  >  Java  >  What are the operation rules of java operators?

What are the operation rules of java operators?

百草
百草Original
2024-01-27 15:25:431195browse

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.

What are the operation rules of java operators?

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.

fc885bea974905c39183518de4989fb6=: Checks whether the value on the left is greater than or equal to the value on the right.

cd4ccd74c159d64aa731acc8afb01297> (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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn