Home > other >  Modulos in learning java [closed]
Modulos in learning java [closed]

Time:09-16

I can't quite wrap my mind around the function of modulos(%). For example '(x % 6) 5' and how it yields a number between 5 and 10. Anything helps, thanks.

CodePudding user response:

Modulo operator gives us the remainder of left / right, like 20/6 will have a remainder of 2. SO x%6 gives us values between 0-5. Adding 5 to it will give us values between 5-10.

CodePudding user response:

modulo operator gives the remainder of a division. For example 10%6 gives 4, since the quotient of 10/6 is 1 and the remainder is 4. Since the remainder is always less than the divisor, x%6 gives a value between 0 and 5. Therefore x%6 5 gives a value between 5 and 10.

  • Related