Java.lang Package Classes

Java Math - floorDiv() Method



The java.lang.Math.floorDiv() method returns the largest integer value that is less than or equal to the algebraic quotient. The method first calculates the quotient by dividing the first argument with the second argument and finally returns the floor() of the quotient. In special cases it returns the following:

  • If the second argument is zero, this method throws ArithmeticException.

Syntax

public static int floorDiv(int x, int y)

Parameters

x Specify the dividend.
y Specify the divisor.

Return Value

Returns the largest integer value that is less than or equal to the algebraic quotient.

Exception

Throws ArithmeticException, if the divisor y is zero.

Example:

In the example below, floorDiv() method returns the floor() of algebraic quotient.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.floorDiv(11, 4));   
  System.out.println(Math.floorDiv(10, 7));
  System.out.println(Math.floorDiv(3, -1));     
 }
}

The output of the above code will be:

2
1
-3

❮ Java.lang - Math

5