Java Program to calculate quotient and reminder

In this program you'll learn, How you can calculate the quotient and reminder of a number (divident) by dividing a number (divisor)

To understand this example, you should have the knowledge of the following Java programming topics:

Calculating Quotient and reminder

A Java program that find Quotient and Reminder is as follow:

import java.util.Scanner;
public class quotient_reminder {
    public static void main(String[] args){
        int dividend, divisor;
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the dividend: ");
        dividend = input.nextInt();
        System.out.print("Enter the divisor: ");
        divisor = input.nextInt();
        int quotient = dividend / divisor;
        int reminder = dividend % divisor;

        System.out.println("Quotient: " + quotient + "\nReminder: " + reminder);
        input.close();
    }
}

Output 1:

Enter the dividend: 11
Enter the divisor: 15
Quotient: 0
Reminder: 11

Output 2:

Enter the dividend: 100
Enter the divisor: 8
Quotient: 12
Reminder: 4

To calculate the Quotient or reminder we first need two number as prerequesties among which the division operation is going to performed to calculate the Quotient or Reminder

Here, we are taking two input from user for some prompt and sotring these value in variable dividend, and divisor. Now in order to calculate the quotient we need to divide a number (divident) by some another number (divisor) the number which we get after performing divison is we get quotient. Thus, here we perform the divison operation using / operator and storing the value in quotient variable.

And what about reminder ? many time the divison isn’t the absolute. So inorder to calculate the reminder we are calculating it using modulas operator and storing it in reminder variable. After getting Quotient and Reminder we just printing these.

Don’t know how to take input from the user ? Look at this examples

Here two input numbers are taken from user one after another with space in between them which distinguish between two different inputs, this useful behavior is because of the default settings of Scanner called as Delimiter, learn more here.