Shaun Shaun - 1 year ago 187
Java Question

Java, Check if integer is multiple of a number

How do I check if a Java integer is a multiple of another number? For example, if

int j
is a multiple of 4.

Answer Source

Use the remainder operator (also known as the modulo operator) which returns the remainder of the division and check if it is zero:

if (j % 4 == 0) {
     // j is an exact multiple of 4
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download