SupportWriter space ↗
← Back to the journal
Basic

How do I get the remainder of a division?

The remainder or modulus operator (%) let you get the remainder of a division of two numbers. This operator can be used to obtain a reminder of an integer or floating point types. package org.kodejava.basic; public class RemainderOperatorDemo { public static void main(String[] args) { int a = 10; double b = 49; // The […]

DWayan · 29 Sep 2009 · 1 min read

Article by Wayan · Source: Kode Java ↗

The remainder or modulus operator (%) let you get the remainder of a division of two numbers. This operator can be used to obtain a reminder of an integer or floating point types.

package org.kodejava.basic;

public class RemainderOperatorDemo {
    public static void main(String[] args) {
        int a = 10;
        double b = 49;

        // The reminder operator (%) gives you the remainder of
        // an integer or floating point division operation.
        System.out.println("The result of " + a + " % 5 = " + (a % 5));
        System.out.println("The result of " + b + " % 9.5 = " + (b % 9.5));
    }
}

Here is the result of the program:

The result of 10 % 5 = 0
The result of 49.0 % 9.5 = 1.5
← Explore more notes