0
What is a modulo?
In java, it says that the symbol % is a modulo. What is that, what are its uses?
4 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.
+ 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.