search
HomeJavajavaTutorialWhat are the operation rules of java operators?

What are the operation rules of java operators?

Jan 27, 2024 pm 03:25 PM
javaoperator

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.

<: check whether the value on left is less than right.>

>=: Checks whether the value on the left is greater 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.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool