Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

%= operator?

 
Randy Trover
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I know the mod operator is %, but what does the %= do? Thanks for any help.
Cheers
Randy
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a %= b is the same as
a = a % b;
where you stuff the result back into the a value that you started with.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works just like '+=', '-=', and all the other math shortcut operators...



Both have the same effect... they assign the modulus of someNum and 5 to someNum...

HTH,
-Nate

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic