Home > Java > JavaBase > body text

What does the '=' symbol in java mean?

Release: 2019-12-07 09:18:26
Original
5751 people have browsed it

What does the '=' symbol in java mean?

= is an assignment operator that assigns a value to a variable, which can then be referenced through the variable. For example:

a = 10; // 将 10 赋给变量 a
Copy after login

The assignment operator refers to the symbol that specifies a numerical value for a variable or constant. The symbol of the assignment operator is "=", which is a binary operator. The operand on the left must be a variable, not a constant or an expression.

The syntax format is as follows:

Variable name = expression content

In the Java language, "variable name" and The types of the "expression" content must match. If the types do not match, they need to be automatically converted to the corresponding type.

The assignment operator has a lower priority than the arithmetic operator, and the combination direction is from right to left; it is not the equal sign in mathematics, it represents an action, that is, the value on the right side is sent to the variable on the left (The left side is only allowed to be variables, not expressions or other forms); do not confuse the assignment operator with the equality operator "==".

The assignment operator is used together with other operators to express the mutation effects of various assignment operations.

For example, on the basis of the basic assignment operator, you can combine arithmetic operators and the bit operators to be learned later to form a compound assignment operator. The meaning of the compound assignment operation composed of assignment operators and arithmetic operators and its usage examples are as follows:

What does the = symbol in java mean?

In large programs, flexible use of these assignment operators can improve Make programs easier to read and make them easier to protect. Below are some examples of using the assignment operator.

int x, y, z; // 定义3个整型的变量
x = y = z = 5; // 为变量赋初值为5
x += 10; // 等价于x=x+10,结果x=15
y -= 3; // 等价于y=y-3,结果y=2
z *= 5; // 等价于z=z*5,结果z=25
x /= 4; // 等价于x=x/4,结果x=3
z %= x; // 等价于z=z%x,结果z=1
Copy after login

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of What does the '=' symbol in java mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!