DEV Community

AmalaReegan
AmalaReegan

Posted on

Day20:Quotient And Remainder in Java;

Quotient And Remainder:

==> The remainder is the integer left over after dividing one integer by another. 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.

Approach:

==> Divide the dividend by the divisor using / operator. Both dividend and divisor can be of any type except string, the result will also be computed accordingly.

==> Get the remainder using % operator. Expressions used in program to calculate quotient and remainder:

Example Program:

package javaprogram;

public class Remainder {

   public static void main(String[] args) 
  {
    // TODO Auto-generated method stub

   int dividend = 555, divisor = 10;
   while (dividend > 4) {
   int remainder = dividend % divisor;
   System.out.println("The Remainder is = "+ remainder);
   // Reduce the dividend by removing the last digit
   dividend=dividend/divisor;
  }
  }
  }
Enter fullscreen mode Exit fullscreen mode

Output:

The Remainder is = 5
The Remainder is = 5
The Remainder is = 5

Enter fullscreen mode Exit fullscreen mode

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs