-16

I've seen code example that had

x += y

and I can't seem to find any explanation for this.

Please help. Thanks.

djred678
  • 5
  • 4

1 Answers1

2

From: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op1.html

You can also combine the arithmetic operators with the simple assignment operator to create compound assignments. For example, x+=1; and x=x+1; both increment the value of x by 1.

Ryan Leach
  • 4,262
  • 5
  • 34
  • 71
  • 1
    Why the -1? you may dislike the question, but I thought this answer helped? – Ryan Leach May 26 '17 at 04:07
  • 2
    I up-voted, but your not technically supposed to answer duplicates, poorly written questions, or any questions that show no research effort. This question seems like all 3 of these things combined. –  May 26 '17 at 07:44
  • 1
    Do you have a source for that? It's news to me. – Ryan Leach May 26 '17 at 07:51
  • 1
    Also I saw a new Stack Overflow user that was looking for guidance, figured giving them an answer, as well as letting them know the etiquette seems a lot less abrasive then giving them no answers and having their question flagged / deleted. This community gets an awful bad rep sometimes with the way it deals with new users. – Ryan Leach May 26 '17 at 07:52
  • 1
    Yes, I do have a source. See [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer). Near the bottom it says _"Answer [well asked](https://stackoverflow.com/help/how-to-ask) questions"_ look at the third bullet point. –  May 26 '17 at 20:10
  • Thanks, I'll try to improve. – Ryan Leach May 27 '17 at 09:25