int a = 5 % 10; System.out.print(a); why is the answer 5? Shouldn't the remainder be 10? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

int a = 5 % 10; System.out.print(a); why is the answer 5? Shouldn't the remainder be 10?

Modulo operator

11th Apr 2020, 4:00 AM
Cyrus X Almani
Cyrus X Almani - avatar
3 Answers
+ 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.
11th Apr 2020, 12:15 PM
Cyrus X Almani
Cyrus X Almani - avatar
0
https://www.sololearn.com/learn/Java/2140/ Formula: Remainder = Decimal * Divisor 5 / 10 = 0.5 0.5 * 10 = 5
11th Apr 2020, 4:30 AM
Rodrigo Aldrete López Hermosa
Rodrigo Aldrete López Hermosa - avatar
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.
11th Apr 2020, 8:11 AM
HonFu
HonFu - avatar