this is excellent question
look in
java the modulus (more correctly, the remainder operator is defined by the following identity)
we are interested to find the value of (x%y)
hence
from above equation
(x%y) = x - (x/y)*y
now from the examples in your code
let x = 1 and y = 2
so
(1%2) = 1 - (1/2)*2
from Right Hand Side (1/2) is integer arithmetic so it results in 0 and 0 * 2 is 0
so Right Hand side is 1 - 0 = 0
and in your code also, 1 % 2 = 0 so this is proved
now taking negative number
(1%-2)
from above equation
(1%-2) = 1 - (1/-2)*(-2)
(1%-2) = 1 - 0*(-2)
(1%-2) = 1 - 0
(1%-2) = 1
similarly you can find values for all ...
hope this helps
happy preparation
SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right