Java Program to Find Quotient and Remainder

In this post, we will learn how to find quotient and remainder using Java Programming language.

This program asks the user two enter the dividend and divisor, then it computes the quotient and remainder using simple arithmetic operators.

So, without further ado, let’s begin this tutorial.

Java Program to Find Quotient and Remainder

// Java Program to Find Quotient and Remainder
import java.util.Scanner;
public class QuoRem{
    public static void main(String[] args){
        int num1, num2, quotient, remainder;
        
        // Asking for input
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the Dividend: ");
        num1 = sc.nextInt();
        System.out.println("Enter the divisor: ");
        num2 = sc.nextInt();
        
        // Computing Quotient and Remainder
        quotient = num1 / num2;
        remainder = num1 % num2;
        
        // Displaying output
        System.out.println("Quotient: " + quotient);
        System.out.println("Remainder: " + remainder);
    }
}

Output

Enter the Dividend: 
30
Enter the divisor: 
7
Quotient: 4
Remainder: 2

How Does This Program Work ?

        int num1, num2, quotient, remainder;

In this program, we have declared four int data type variables named num1, num2, quotient and remainder.

        // Asking for input
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the Dividend: ");
        num1 = sc.nextInt();
        System.out.println("Enter the divisor: ");
        num2 = sc.nextInt();

Then, the user is asked to enter the dividend and divisor.

        quotient = num1 / num2;

We calculate the quotient of the two numbers using the division (/) operator. It divides one value by another and returns a quotient.

        remainder = num1 % num2;

Similarly, we calculate the remainder using the Modulus (%) operator. Modulus operators return remainder after division.

        // Displaying output
        System.out.println("Quotient: " + quotient);
        System.out.println("Remainder: " + remainder);

Finally, the quotient and remainder is displayed on the screen using System.out.println() function.

Conclusion

I hope after going through this post, you understand how to find quotient and remainder using Java Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.

Also Read:

Leave a Comment

Your email address will not be published.