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
2
u/[deleted] Mar 27 '21
% (modulus) is the remainder operator. So basically if X is divisible by Y evenly it will return 0.
10 % 2 = 0 or 10/2 = 5 with no remainder.
3 ÷ 4 = 0.75
3 things cannot be divided evenly between 4 people so the remainder is 3.
20 % 2 = 0 or 10 ÷ 2 = 10 with nothing left over. 20 candies can be shared evenly between 10 people without having anything left over. 0 remainder.
The modulus operator returns the remainder of the two numbers after division. If you are provided with two numbers, say, X and Y, X is the dividend and Y is the divisor, X mod Y is there a remainder of the division of X by Y.