Java Math - floorMod() Method
The Java floorMod() method returns floor modulus of the arguments. The floor modulus of two arguments is same as modulo 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 example below, 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:
3 3 0
❮ Java Math Methods