views:

170

answers:

4

In Java what does += do or mean?

for example:

devtop += Math.pow(x[i] - mean, 2);
+2  A: 

It will add the result of the operation Math.pow(x[i] - mean, 2) to the devtop variable.

A more simple example:

int devtop = 2;
devtop += 3; // devtop now equals 5
James Skidmore
+7  A: 

It's a compound assignment operator. It's equivalent to:

devtop = devtop + Math.pow(x[i] - mean, 2);

In general, x $= y where $ is an operator is identical to x = x $ y.

Mehrdad Afshari
(Except where `$ == = | ! == $`. There's also a matter of casting, but that's just odd.)
Tom Hawtin - tackline
Also, when $ == . | $ == [] | $ == much more stuff but it demonstrates the point.
Mehrdad Afshari
+19  A: 

a += b is short hand for a = a + b

Svend
+1  A: 

Add Math.pow(x[i] - mean, 2) to devtop.

adatapost