r/javahelp • u/macetfromage • Mar 27 '21
Solved 1%2=1?
i dontunderstand the results when the nr to the right is larger
ofc 4%3=1
but why 3%4=3
2
Upvotes
r/javahelp • u/macetfromage • Mar 27 '21
i dontunderstand the results when the nr to the right is larger
ofc 4%3=1
but why 3%4=3
17
u/rQbTheMan Mar 27 '21 edited Mar 27 '21
% stands for modulus. The answer of doing a % b is the remainder of dividing a by b. 1%2 is basically 1 divided by 2 and the remainder of that would be 1
Forgot to add: you multiply the result of 1/2 by the divisor(2) so its 0.5 x 2 =1. For 3%4 it would be 3/4 = 0.75, then 0.75 x 4 = 3 so 3%4 = 3