What is a modulo? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is a modulo?

In java, it says that the symbol % is a modulo. What is that, what are its uses?

15th Apr 2020, 2:57 AM
Carl Hunter Toler
Carl Hunter Toler - avatar
3 Answers
+ 5
Modulo Operator is one of the fundamental operators in Java. It's a binary operator. it requires two operands. In a division operation, the remainder is returned by using modulo operator. It is denoted by % (percentage) sign. For example 5%2 will return 1 because if you divide 5 with 2, the remainder will be 1.
15th Apr 2020, 5:06 AM
SHADOW 🌀
SHADOW 🌀 - avatar
+ 1
An example: 33 / 5 = 6, with a remainder of 3. Therefor 33 % 5 = 3. Modulo is used pretty much everywhere (just like + and -), it's hard to narrow down usecases. You should be pretty familiar with modular arithmetic already, from telling time: It's 5am now, how late is it in 8 hours? It's 1. Which is just (5+8)%12. I like to visualize modular calculations as wrapping the number line around a circle and reading results off that, much like an analog clock.
15th Apr 2020, 4:55 AM
Schindlabua
Schindlabua - avatar