# Program to find Quotient And Remainder in Java

The *remainder* is the integer left over after dividing one integer by another. The *quotient *is the quantity produced by the division of two numbers.

For example,

(7/2) = 3In the above expression 7 is divided by 2, so the quotient is 3 and the remainder is 1.

**Approach**: Divide the *dividend* by the *divisor* using **/** operator. Both dividend and divisor can be of any type except string, the result will also be computed accordingly. Get the remainder using % operator.

Expressions used in program to calculate quotient and remainder:

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

**Note:** The program will throw an ArithmeticException: / by zero when divided by 0.

**Explanation**:

Consider

Dividend = 100andDivisor = 6Therefore,

Quotient= 100/6 = 16

Remainder= 100%6 = 4

Below programs illustrate the above approach:

**Program 1:**

`public` `class` `QuotientAndRemainder { ` ` ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` ` ` `int` `dividend = ` `556` `, divisor = ` `9` `; ` ` ` ` ` `int` `quotient = dividend / divisor; ` ` ` `int` `remainder = dividend % divisor; ` ` ` ` ` `System.out.println(` `"The Quotient is = "` `+ quotient); ` ` ` `System.out.println(` `"The Remainder is = "` `+ remainder); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

**Output:**

The Quotient is = 61 The Remainder is = 7

**Program 2:** For a negative number.

`public` `class` `QuotientAndRemainder { ` ` ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` ` ` `int` `dividend = -` `756` `, divisor = ` `8` `; ` ` ` ` ` `int` `quotient = dividend / divisor; ` ` ` `int` `remainder = dividend % divisor; ` ` ` ` ` `System.out.println(` `"The Quotient is = "` `+ quotient); ` ` ` `System.out.println(` `"The Remainder is = "` `+ remainder); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

**Output:**

The Quotient is = -94 The Remainder is = -4

**Program 3:** This program will throw an ArithmeticException as the divisor = 0.

`public` `class` `QuotientAndRemainder { ` ` ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` ` ` `int` `dividend = ` `56` `, divisor = ` `0` `; ` ` ` ` ` `int` `quotient = dividend / divisor; ` ` ` `int` `remainder = dividend % divisor; ` ` ` ` ` `System.out.println(` `"The Quotient is = "` `+ quotient); ` ` ` `System.out.println(` `"The Remainder is = "` `+ remainder); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

**Output:**

Exception in thread "main" java.lang.ArithmeticException: / by zero at QuotientAndRemainder.main(QuotientAndRemainder.java:7)

## Recommended Posts:

- C Program to Compute Quotient and Remainder
- BigInteger remainder() Method in Java
- Java Program for Program to find area of a circle
- Java Program to find whether a no is power of two
- Java Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Java Program to find sum of array
- Java Program to find transpose of a matrix
- Java Program to Find sum of Series with n-th term as n^2 - (n-1)^2
- Java Program to Find sum of even factors of a number
- Java Program for Find the perimeter of a cylinder
- Java Program to find largest element in an array
- Java Program to Find minimum sum of factors of number
- Java Program to Find reminder of array multiplication divided by n
- Java Program for Find largest prime factor of a number
- Java Program to Find the closest pair from two sorted arrays

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.