Java Program to find quotient and remainder


In this program, You will learn how to find quotient and remainder in java.


2 = 10 / 5

0 = 10 % 5

Example: How to find quotient and remainder in java.

import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        int q,r,a,b;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter two numbers:");
        a = sc.nextInt();
        b = sc.nextInt();

        q = a / b;
        r = a % b;

        System.out.println("Quotient is:"+q);
        System.out.println("Remainder is:"+r);

    }
}

Output:

Enter two numbers:10 5
Quotient is:2
Remainder is:0