+ 1
int a = 5 % 10; System.out.print(a); why is the answer 5? Shouldn't the remainder be 10?
Modulo operator
3 Respuestas
+ 2
Thank you both! I see where I went wrong. We're dividing by a bigger number. The remainder comes from the dividend not the divisor.
0
https://www.sololearn.com/learn/Java/2140/
Formula:
Remainder = Decimal * Divisor
5 / 10 = 0.5
0.5 * 10 = 5
0
If you translate modulo to regular language, you could say:
If I divide 5 by 10 as often as possible, what will be left over?
5 can be divided by 10 zero times, then 5 is left over.