Facebook Page Twitter Page LinkedIn Page
× Java Tutorial Java Advanced Java Resources


The Java Math floorMod() method is used to return floor modulus of the arguments. The floor modulus of two arguments is same as modulus of two arguments. The method can be overloaded and it can take int and long arguments. In special cases it returns the following:

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

Syntax

public static int floorMod(int x, int y)
public static long floorMod(long x, long y)

Parameters

x Specify the dividend.
y Specify the divisor.

Return Value

Returns the floor modulus of the arguments.

Exception

throws ArithmeticException, if the divisor y is zero.

Example:

In the below example, floorMod() method is used to return the floor modulus (remainder) of two arguments.

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

The output of the above code will be:

3
3
0

❮ Java Math Methods