How to Find Quotient and Remainder in Java Program ?

  Java Interview Q&A

Dear reader, today we will read in Java program to find Quotient and Remainder, when one number is divided by another number.

To find the quotient we divide num1 by the num2 / div operator. Since both the variable number 1 and number 2 are integers, the result of 15/2 will be an integer even if the result is 7.5 mathematically. So the value assigned to the variable quotient after the operation is 7.

To find the remainder, we use the% operator. The remaining 15/2 i.e. 1 is assigned to the remaining variables after the operation.

At the end of the program, the variable’s value quotient and the remainder are printed.

Java Program to find Quotient and Remainder

In the following program we have two integer numbers num1 and num2 and we are finding the quotient and the remainder when num1 is divided by num2, we can say that num1 is the dividend here and num2 is the divisor.

public class JavaExample {
    public static void main(String[] args) {
        int num1 = 15, num2 = 2;
        int quotient = num1 / num2;
        int remainder = num1 % num2;
        System.out.println("Quotient is: " + quotient);
        System.out.println("Remainder is: " + remainder);
    }
}

Output:

Quotation is : 7
Remainder is : 1

Read here complete . JAVA Program Tutorial

LEAVE A COMMENT