Join our newsletter for the latest updates.
Java Program to Compute Quotient and Remainder

Java Program to Compute Quotient and Remainder

In this program, you'll learn to compute quotient and remainder from the given dividend and divisor in Java.

To understand this example, you should have the knowledge of the following Java programming topics:

Example: Compute Quotient and Remainder

public class QuotientRemainder {

    public static void main(String[] args) {

        int dividend = 25, divisor = 4;

        int quotient = dividend / divisor;
        int remainder = dividend % divisor;

        System.out.println("Quotient = " + quotient);
        System.out.println("Remainder = " + remainder);


Quotient = 6
Remainder = 1

In the above program, two numbers 25 (dividend) and 4 (divisor) are stored in two variables dividend and divisor respectively.

Now, to find the quotient we divide dividend by divisor using / operator. Since, both dividend and divisor are integers, the result will also be computed as an integer.

So, mathematically 25/4 results 6.25, but since both operands are int, quotient variable only stores 6 (integer part).

Likewise, to find the remainder we use the % operator. So, the remainder of 25/4, i.e. 1 is stored in an integer variable remainder.

Finally, quotient and remainder are printed on the screen using println() function.