floorDiv() long int in Java

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

Syntax:

long java.lang.Math.floorDiv(long x, int y)

This method takes two parameters as an argument first argument is of type long, while the second argument is of type int. This method returns the largest (closest to positive infinity) long value that is less than or equal to the algebraic quotient. 

Note: There is one special case if the dividend is the Long.MIN_VALUE and the divisor is -1, then integer overflow occurs and the result is equal to Long.MIN_VALUE.

Parameters: Two parameters are required for this method.

x: the dividend.

y: the divisor.

Returns: the largest (closest to positive infinity) int value that is less than or equal to the algebraic quotient.

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

Approach

Java

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

        long x = 1717177782;
        int y = 5;

        System.out.println(Math.floorDiv(x, y));
    }
}

Output:

343435556

No comments:

Post a Comment