r/javahelp • • 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

13 comments sorted by

View all comments

1

u/[deleted] Mar 28 '21 edited Mar 28 '21

% sign is the modulus operator. It gives you the remainder amount. Basically it displays the left over amount from a division

In division 4 / 4 = 1

but using modulo division...

4 % 4 = 0 because 4 divides into 4 perfectly, there is no remainder

Therefore 3 % 4 = 3 because 3 divides into 4 zero times with a remainder left over of 3

4 % 3 = 1 because 4 divides into 3 three times with a remainder left over of 1