简体   繁体   English

在Java中,“ / =”是什么意思?

[英]What does “/=” mean in Java?

I was checking some code online when i found the following statement 我发现以下语句时正在在线检查一些代码

number /= 10;

I know that / mean divison and = is the assignment operator but i don't understand what it does in this case. 我知道/ mean divison和=是赋值运算符,但在这种情况下我不明白它的作用。

It means that whatever the value number contains will be divided by 10 and the result will be stored back into number. 这意味着无论数值中包含什么值,都将被除以10,结果将存储回数字中。

It is exactly equivalent to 完全等同于

number = number / 10

Most of the major operators have it: 大多数主要运营商都拥有它:

number *= 10
number += 10
number -= 10
number %= 10
number >>= 10
number <<= 10

It means 它的意思是

number =number/10;

Number divided by 10 数除以10

you can also do 你也可以

 number operator=number

where operator can be + , / , * 运算符可以为+/*

This is the shorter notation for number = number / 10; 这是number = number / 10; The same exists for the other operators as well: 其他运算符也存在相同的情况:

x += y; => x = x + y; => x = x + y;
x -= y; => x = x - y; => x = x - y;
x *= y; => x = x * y; => x = x * y;
x %= y; => x = x % y; => x = x % y;

It is equivalent of - 它等效于-

number = number / 10;  

It is a composite operator - consist of division and assignment. 它是一个复合运算符-由除法和赋值组成。 You may found something like this - 您可能会发现类似这样的内容-

+=
-=
%=  etc.

All of these above works similarly. 以上所有这些都类似地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM