• Post Reply Bookmark Topic Watch Topic
  • New Topic

% operator  RSS feed

 
Janki Shah
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone help me with how the % operator works?
how come 5 % 7 = 5?
Is there any rules some where about this I can refer to?
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple math, it's the modulus operator.

In integer division 5 / 7 = 0 with a remainder of 5.

% gives you the remainder.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janki Shah wrote:
Is there any rules some where about this I can refer to?

http://docs.oracle.com/javase/tutorial/java/index.html
and in particular,
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html,
and in even more particular,
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op1.html
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More details in the Java Language Specification.
 
Janki Shah
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!