HomeJavaJava Program to Compute Quotient and Remainder

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

You May Also Like

Java is a popular programming language that is used to develop a wide range of applications. If you are a...
  • Java
  • March 6, 2023
Java is a programming language and computing platform that is used to create various types of applications. It is used...
  • Java
  • March 6, 2023
In this post, you’ll learn how to download and install JUnit in Eclipse so that you can use in your...
  • Java
  • October 9, 2022