Java Program to Compute Quotient and Remainder

Write a Program to Compute Quotient and Remainder

public class CalculateQuotientRemainder {

    public static void main(String[] args) {

        int dividend = 27, divisor = 5;

        int quotient = dividend / divisor;
        int remainder = dividend % divisor;

        System.out.println("Quotient is = " + quotient);
        System.out.println("Remainder is= " + remainder);
    }
}

Output

Quotient is = 5
Remainder is= 2

In the above program, dividend 27 is divided by divisor is 5. in addition, If we see mathematically 27/5 result is 5.4 but here quotient and reminder both are defined as int so, quotient part will only store integral part 5.

likewise, we use % operator to find integer part, ie. 2.

the final two lines are for printing the Quotient and reminder.

Leave a Reply