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.

Example: Compute Quotient and Remainder

  1. public class QuotientRemainder {
  2. public static void main(String[] args) {
  3. int dividend = 25, divisor = 4;
  4. int quotient = dividend / divisor;
  5. int remainder = dividend % divisor;
  6. System.out.println("Quotient = " + quotient);
  7. System.out.println("Remainder = " + remainder);
  8. }
  9. }

When you run the program, the output will be:

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.