Java Program to Find Quotient And Remainder

In this java program, we will learn about how to compute the quotient and reminder of two numbers in Java.

In a fraction, the numerator is dividend, denominator is divisor, and when numerator is divided by the denominator, the result will be quotient and the value which is left after division is remainder.

For Example:
(5/2) = 2.
In this expression 5 is dividend, 2 is divisor, the result of division 2 is quotient and remainder is the value left after division which is 1.

To understand this java program, you should have understanding of the following Java programming concepts:

In Java program, Quotient and Reminder can be calculated using two simple formula
  • Quotient = Dividend / Divisor
  • Remainder = Dividend % Divisor
If Divisor is zero, then java program will throw ArithmeticException.

Java Programs to Compute Quotient and Remainder

public class QuotientAndRemainder {
  public static void main(String[] args) {
    int dividend = 11, divisor = 3;

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

    System.out.println("Quotient: " + quotient);
    System.out.println("Remainder: " + remainder);
  }
}
Output
Quotient: 3
Remainder: 2

  • In above java program, first of all we initialize two Integer variables "dividend" and "divisor" with 11 and 3 respectively. Here, we are dividing 11 by 3.
  • To find the quotient, we have used / operator. We have divided dividend (11) by divisor (3). Since both dividend and divisor are integers, the result will also be an integer. The result is stored in another integer variable "quotient".
  • Similarly, to find the remainder we have used % operator. We have divided dividend (11) by divisor (3) and the result is stored in another integer variable "remainder".
  • At last, we print the value of "quotient" and "remainder" on standard output(screen) using System.out.println() method.