DEV Community

vimala jeyakumar
vimala jeyakumar

Posted on

Modulo or Remainder in java

Remainder:

-->Modulo or Remainder Operator returns the remainder of the two numbers after division.
-->If you are provided with two numbers, say A and B, A is the dividend and B is the divisor, A mod B is there a remainder of the division of A and B.
-->Modulo operator is an arithmetical operator which is denoted by %.
NOTE:
If numerator is less than denominator then % will give output as the numerator only.

Syntax:

A % B
Where A is the dividend and B is divisor

quotient = dividend / divisor;
remainder = dividend % divisor;
Enter fullscreen mode Exit fullscreen mode

Quotient:

The quotient is the quantity produced by the division of two numbers. For example,
-->(7/2) = 3 In the above expression 7 is divided by 2, so the quotient is 3 and the remainder is 1.

Example Program:

package programs;

public class Reminder {

    public static void main(String[] args) 
    {
        int no = 6547;

        while(no>0)
        {
            System.out.println(no%10);// 5 4 3 2

            no=no/10;//123 12 1
        }

    }

}

Enter fullscreen mode Exit fullscreen mode

Output:
7
4
5
6
example program:

package programs;

public class Reminder {

    public static void main(String[] args) 
    {
        int no = 6547;
        int reminder;
        int quotient;
        while(no>0){

            reminder=no%10;// 5 4 3 2
            System.out.println("Reminder: "+reminder);
            quotient=no/10;//123 12 1
            System.out.println("Quotient: "+quotient);
            no=quotient;
        }


    }
}
Enter fullscreen mode Exit fullscreen mode

Output:
Reminder: 7
Quotient: 654
Reminder: 4
Quotient: 65
Reminder: 5
Quotient: 6
Reminder: 6
Quotient: 0

Reference:

https://www.geeksforgeeks.org/program-to-find-quotient-and-remainder-in-java/
https://www.geeksforgeeks.org/modulo-or-remainder-operator-in-java/
https://www.tpointtech.com/write-a-program-to-find-the-quotient-and-remainder

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more