Trusted answers to developer questions

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

**Floor division** is a regular division operation, except it yields the

- If the dividend and divisor are
`Integer.MIN_VALUE`

and`-1`

, respectively, then the division operation results in integer overflow. Hence, the result will be`Integer.MIN_VALUE`

. - If the dividend and divisor are of the same sign, then the results of
`floorDiv`

and the normal division operation are the same. - If the dividend and divisor are of different signs, then
`floorDiv`

returns the integer less than or equal to the quotient, and normal division returns the integer closest to zero.

- dividend - 23
- divisor - 4

The fractional representation would be $23/4$.

The normal division operation results in $5.75$ as the quotient.

The floor division operation results in $5$ as the quotient.

- dividend - -23
- divisor - 4

The fractional representation would be $-23/4$.

The normal division operation results in $5.75$ as the quotient.

The floor division operation results in $-6$, as the quotient because the signs of the dividend and divisor are different.

The `floorDiv`

method is introduced in Java 8.

`floorDiv`

is defined in the `Math`

class, which is defined in the `java.lang`

package.

To import the `Math`

class, use the import statement below:

```
import java.lang.Math;
```

```
public static int floorDiv(int x, int y)
```

`int x`

: dividend`int y`

: divisor

The `floorDiv`

method returns the largest value that is less than or equal to the algebraic quotient.

`public static long floorDiv(long x, int y)`

`public static long floorDiv(long x, long y)`

import java.lang.Math;public class Main{public static void main(String[] args){int dividend = 23;int divisor = -4;int quotient = Math.floorDiv(dividend, divisor);System.out.printf("floorDiv(%d, %d) = %d", dividend, divisor, quotient);System.out.println();dividend = 23;divisor = 4;quotient = Math.floorDiv(dividend, divisor);System.out.printf("floorDiv(%d, %d) = %d", dividend, divisor, quotient);}}

RELATED TAGS

java

communitycreator

CONTRIBUTOR

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses