简体   繁体   English

我需要符号 += 的帮助

[英]I need help for symbol +=

I am beginner and I want ask the meaning of this symbol:我是初学者,我想问这个符号的含义:

I know that this:我知道这个:

i++ ------> is this i=i+1 i++ ------> 这是i=i+1

but this:但是这个:

+= -------> what is? += -------> 是什么?

Do you know other rare symbols (aka operators)?你知道其他稀有符号(又名运算符)吗?

x+=y

is not a rare piece of notation at all.根本不是一个罕见的符号。 It's just a shortened version of the following:它只是以下内容的缩短版本:

x = x + y

It's just a shorter variant of base math function.它只是基础数学函数的一个较短的变体。

a += 5   =>   a = a + 5;
a += 1   =>   a = a + 1   =>   a++ // special case of the code abode, incrementation is allowed by this shorter code

a *= 2   =>   a = a * 2

a -= 1   =>   a = a - 1   =>   a--
a -= 2   =>   a = a - 2 

etc.等等。

Some time we need to modify same variable value and reassigned it to same reference variable.有时我们需要修改相同的变量值并将其重新分配给相同的引用变量。 Java allows you to combine assignment and addition operators using a shorthand operator . Java 允许您使用速记运算符组合赋值和加法运算 For example, the preceding statement can be written as:例如,前面的语句可以写成:

i +=8; //This is same as i = i+8;

+= goes under assignment operator category like += 属于赋值运算符类别,如

 += -= *= /= %= &= ^= |= <<= >>= >>>=

means方法

+= addition and assignment operator +=加法和赋值运算符

x +=y; as same as x= x+y;x= x+y;

i++、i=i+1 和 i+=1 都是一回事。

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

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