floorMod() long in Java

floorMod(): This method is available in the Math class of Java.

Syntax:

long java.lang.Math.floorMod(long x, long y)

This method takes two arguments of type long. This method returns the floor modulus of the long arguments.

Note:

1. The floor modulus is x - (floorDiv(x, y) * y),has the same sign as the divisor y, and is in the range of -abs(y) < r < +abs(y).

2. The relationship between floorDiv and floorMod is such that:

floorDiv(x, y)* y + floorMod(x, y) == x

Parameters: Two parameters are required for this method.

x: the dividend.

y: the divisor

Returns:the floor modulus x - (floorDiv(x, y) * y)

Note: Throws:ArithmeticException - if the divisor y is zero.

For Example:

Math.floorMod(1883728711, 81818) = > It returns 32897.

Approach

Java

public class FloorModLong {
    public static void main(String[] args) {

        long x = 1883728711, y = 81818;
        System.out.println(Math.floorMod(x, y));

    }
}

Output:

32897

No comments:

Post a Comment