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

The Java Math floorMod() method returns 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.


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


x Specify the dividend.
y Specify the divisor.

Return Value

Returns the floor modulus of the arguments.


throws ArithmeticException, if the divisor y is zero.


In the below example, floorMod() method returns 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:


❮ Java Math Methods