Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

What does it mean when a variable is defined as i += 100?

+15 votes
asked Dec 8, 2015 in (Winter 15-16) by Emily Mueller (100 points)

3 Answers

+6 votes

x += a;  

is a Java shorthand for 

x = x + a; 

so

i += 100

does the same thing as

i = i + 100

answered Dec 8, 2015 by Forrest Stonedahl (100 points)
+1 vote
This convention does not only work with addition as well. It also will work with -, +, and *. Quite honestly it could work for other operators, but those are the four I am familiar with.
answered Dec 10, 2015 by Michael Dimock (100 points)
+1 vote
Honestly when X+= 6 is stated, the computer "thinks" take whatever is in the "X" box and add 6. Then, put that new value back into the "X" box.
answered Dec 10, 2015 by Eric DeMattia (100 points)
...