Taken from "Objects first in java 2006"
QUOTE
The modulo operator
The last method in the NumberDisplay class increments the display value by 1. It takes care that the value resets to zero when the limit is reached:
public void increment()
{
value = (value + 1) % limit;
}
This method uses the modulo operator (%). The modulo operator calculates the remainder of an integer division. For example, the result of the division
27 / 4
can be expressed in integer numbers as
result = 6 remainder = 3
The modulo operator returns just the remainder of such a division. Thus the result of the expression ( 27 % 4) would be 3.
The example it gives (27 / 4) and the increment function to me dont seem to relate and this is where I'm confused as to why or how modulo is suppose to work. The increment function will increase 'value' by 1 everytime its run untill it reaches an int 'limit' then resets to zero. Well thats how it works but I'm still confused.
For another reason the example is (27 / 4) where as the function would be ((lower number + 1) % limit ). A lower number on the left side % by limit which is a higher number.
/sigh someone help explain this to me so I can figure this out.


