Java Math - floorMod() Method
The java.lang.Math.floorMod() method returns floor modulus of the arguments. The floor modulus of two arguments is same as modulo of two 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)
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.
import java.lang.*; 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.lang - Math