int remainder = a % b; will sort you. The remainder operator returns the remainder of the division.
Note that the remainder operator is also called the modulo operator. However, this is incorrect for Java as Java will return a negative value if the left operand a is negative.