Let us check some use cases: Checking if a number is even or odd: package com.nullbeans. The ‘%’ operator can be used in many situations within a Java program. result = 5Īnother way to describe the modulus operation is that it finds out the first remaining number which is smaller than the divisor, if we repeatedly subtracted the divisor from the numerator.įor example: 23 - 6 = 17 // Still larger than the divisor (6), try again.ġ7 - 6 = 11 // Still larger than the divisor (6), try again.ġ1 - 6 = 5 // Number is smaller than the divisor (6).
An example usage of the operator in Java can be as follows: package The result should be the remainder that would remain if we had divided the first number by the divisor.
Converting everyday terms to math, an even number is one where it’s 0 mod 2 that is, it has a remainder of 0 when divided by 2. The division () / () in Scratch is not limited to giving out whole numbers. It's what remains, after having given each person the same largest possible number of whole apples. That's what the mod operator calculates: 6 mod 4 is 2. MOD is nothing but MODULO is a mathematical operation. For example, 5 mod 3 2 which means 2 is the remainder when you divide 5 by 3. You can give out 1 apple to each, then you have 2 left. In VBA MOD is same as to the application in mathematics, when a number is divided by its divisor and we get a reminder from that division, this function is used to give us that remainder from the division, it is not a function in VBA rather than it is an operator. The first is the number on which the operator will be applied upon and the second is the divisor. The modulo operation (abbreviated mod, or in many programming languages) is the remainder when dividing. 4 Related Posts How to use the ‘%’ operator