Java Math floorDiv() Method

The floorDiv () method of Math class returns the largest integer value that is less than or equal to the algebraic quotient. It firstly divides the dividend and divisor and then returns an integer that is less or equal to the quotient.

Syntax:

  1. public static int floorDiv(int x, int y)
  2. public static long floorDiv(long x, int y)
  3. public static long floorDiv(long x, long y)

Parameters:

The parameter ‘x’ and ‘y’ represents the dividend and the divisor.

Return Value:

The floorDiv () method returns the largest integer value that is less than or equal to the algebraic quotient.

  • It returns the result same as the first argument, if the first argument passed is equal to an integer or long value and second argument is -1.
  • It throws an Arithmetic Exception, if the divisor is zero.

Example 1:

Output:

Example 2:

Output:

Example 3:

Output:

Example 4:

Output:

Example 5:

Output: