Is +=
the same as =+
?
I can't find any reason for why the plus sign is reversible. For what reasons would I need to use one of the other? Where can i find docs on this i tried searching but didnt see the use of both.
=+ does nothing; it's the same as = here. You have just written sum1 = two . sum2 += one on the other hand is essentially the same as sum2 = sum2 + one .
It's the Addition assignment operator. Let's understand the += operator in Java and learn to use it for our day to day programming. x += y in Java is the same as x = x + y. It is a compound assignment operator.
The plus-equals operator ( += ) adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left.
== operator is a type of Relational Operator in Java used to check for relations of equality. It returns a boolean result after the comparison and is extensively used in looping statements and conditional if-else statements.
It's not the same.
x+=5
is equivalent to x=x+5
.
x=+5
(or x=(+5)
) is equivalent to x=5
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With