FREE E LEARNING PLATFORM
HOMEEXCEPTIONSOOPSJVMINTRO
 

Find Quotient and Remainder


In the following program we have two integer numbers num1 and num2 and we are finding the quotient and remainder when num1 is divided by num2, so 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

Qotient is 7 
Remainder is 1

To compute the quotient and remainder we have created two variables with the name quotient and remainder respectively.

To find the quotient we divide the num1 by num2 using / operator. Since both the variables num1 & num2 are integers, the result will be integer despite the fact that the result of 15/2 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 remainder of 15/2 i.e 1 is assigned to the variable remainder after operation.

At the end of the program the values of variables quotient and remainder are printed.

You may also Find this interesting

Program to find leap year

Program to find prime number

Program to find all the prime numbers

Program to Display Area of a Rectangle

Program to Display Area of a Triangle

Program to Display Area of a Circle

Program to Display Vowels and Constant counts