Java Math floorDiv() Method
Example
Perform integer divisions:
System.out.println(Math.floorDiv(10, 5));
System.out.println(Math.floorDiv(10, 4));
System.out.println(Math.floorDiv(-10, 4));
System.out.println(Math.floorDiv(-10, 5));
Try
it Yourself »
Definition and Usage
The floorDiv()
method returns the division between two integers rounded
down. This is different from an ordinary integer division in that negative results are rounded down away from
zero instead of truncated towards it.
Syntax
One of the following:
public static int floorDiv(int dividend, int divisor)
public static long floorDiv(long dividend, long divisor)
Parameter Values
Parameter | Description |
---|---|
dividend | Required. The dividend of the division. |
divisor | Required. The divisor of the division. |
Technical Details
Returns: | An int or long value
representing a division between two integers. |
---|---|
Throws: | ArithmeticException - If the divisor is zero. |
Java version: | 1.8+ |
❮ Math Methods