Java Program to find Quotient & Remainder

In this post, we are going to write a simple Java Program to find the Quotient & Remainder. Before writing the program, let’s see what is a Remainder and a Quotient in mathematics?.

Here is an example:
45           ÷         7           =           6           and           3
Dividend Divisor Quotient Remainder

In the above example, 45 is the Dividend, 7 is the Divisor, 6 is the Quotient and 3 is the Remainder.

So the remainder is the “left over” value after dividing one integer by another. Quotient is the quantity produced by the division of 2 integers.

So in Java Program we can achieve this by using the / and % operators, see the below expressions

quo = dividend / divisor -> will give the quotient
rem = dividend % divisor -> will give the remainder

Let’s write the Java Program now:


import java.util.Scanner;

/**
 *
 * @author agur
 */
public class QuoRem {
    public static void main(String[] args){
        
        int dividend, divisor, quo, rem;
        Scanner in = new Scanner(System.in);
        
        //get the dividend value
        System.out.print("Enter Dividend:");
        dividend = in.nextInt();
        
        //get the divisor value 
        System.out.print("Enter Divisor:");
        divisor = in.nextInt();
        
        //find quotient 
        quo = dividend / divisor;
        
        //find reminder
        rem = dividend % divisor;
        
        //print the result
        System.out.println("Quotient: "+quo);
        System.out.println("Remainder: "+rem);
    }
}

Output of the above program:

Enter Dividend:45
Enter Divisor:7
Quotient: 6
Reminder: 3

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top