For rem operator, Sign of the result is same as sign of x. The remainder (rem) and modulus (mod) are defined as follows:
Previous Next Home rem(X,Y) = X –(X/Y)*Y (in which X/Y in an integer)
mod(X,Y) = X – Y * N (in which N is an integer)
*Main> rem 10 (-3)
1
*Main>
*Main> mod 10 (-3)
-2
For positive integers both mod and rem behave like same.
*Main> rem 10 3
1
*Main> mod 10 3
1
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here