Return to Topic Menu | Computer Science Main Page | MathBits.com  | Terms of Use

Primary Math Operators

-

*

/

Addition 

Subtraction

Multiplication

Division

Modulus (also called remainder)

Did you notice that there is no symbol for "exponent"?

 

The MODULUS Operator %

The modulus operator produces the remainder of dividing the first value by the second value.  For example:

22 % 6 = 4   because 22 / 6 = 3 with a remainder of 4

When using Modulus,
BOTH operands MUST be INTEGER TYPES!!!!


Confusing DIVISIONS

Be careful when performing integer division.  When dividing an integer by an integer, the answer will be an integer (not rounded).

Compare these divisions:  (5 is an integer while 5.0 is a double)

Integer division  8 / 5 = 1
Double division  8.0 / 5.0 = 1.6
Mixed division 8.0 / 5 = 1.6

When an operation involves two types (as the mixed division shown above), the smaller type is converted to the larger type.  In the case above, the integer 5 was converted to a double type before the division occurred.

Return to Topic Menu | Computer Science Main Page | MathBits.com  | Terms of Use