Modulo Operator is one of the fundamental operator in Java. It's a binary operator i.e. it require 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, remainder will be 1. For a programmer it's very important to know how to use this operator, they are very important to build logic. For example, in many cases like
reversing a number or
checking if a number is palindrome, you can use modulus operator with 10 to get the last digit, for example 101%10 will return 1 or 1234%10 will return 4, the last digit. It is one of the rather less used arithmetic operator in comparison of +, -, * and /. One of the important point about the remainder operator which is not know by many Java programmer is that it can also be used with floating point numbers. It's surprising because you don't normally think of real number division as producing remainders. However there are some times when it's useful to ask exactly how many times does 2.5 go into 7.5 and what's left over? The answer is that 2.5 goes into 7.5 three times with zero left over, and it's that zero which is the result of 7.5 % 2.5 in Java. Another good use of modulus operator is to check if a number is even or odd. In case of even number, number%2 will return 0, while if a number is odd then number%2 will return 1.