Java Program to Compute Quotient and Remainder

In this Java program, let’s learn how to compute quotient and remainder in your Java sourcecode

How to Compute Quotient and Remainder in JAVA? 

RUN CODE SNIPPET

Example: To find Quotient and Remainder

public class Main {
  public static void main(String[] args) {
    int num1 = 50, num2 = 3;
    int quotient = num1 / num2;
    int remainder = num1 % num2;
    System.out.println("Quotient = " + quotient);
    System.out.println("Remainder = " + remainder);
  }
}

OUTPUT

Quotient = 16 
Remainder = 2

In the above program, the integers 50 and 3 are stored in the variable num1 and num2. 

The number 50 is dividend and 3 is the divisor. We are calculating the Quotient and remainder by dividing 50 by 3. 

Here we use the “/” operator to find the quotient and the “%” operator to find the remainder. Since both the dividend and divisor are integers, the result also is an integer.  

Using the println function we print the result on the screen.

Share:

Leave A Reply

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

You May Also Like

In this Java program, we will learn how to find the GCD of two numbers using Java.  GCD (Greatest Common...
  • Java
  • December 3, 2024
In this Java Program, you’ll learn how to swap two numbers using the Java programming language.  How to Swap Two...
  • Java
  • December 2, 2024
In this Java program , we will learn how to Find Largest Element in an Array in your Java program.   How to Find Largest Element...
  • Java
  • December 2, 2024