absExact() int in Java

int java.lang.Math.absExact(int a)

This function returns the mathematical absolute value of an int value if it is exactly representable as an int. This function throwing ArithmeticException if the result overflows the positive int range. The mathematical absolute value of Integer.MIN_VALUE overflows the positive int range, so an exception is thrown for that argument. 

Parameters: One parameter is required for this function.

arg: The argument whose absolute value is to be determined.

It returns the absolute value of the argument unless overflow occurs

Throws: ArithmeticException - if the argument is Integer.MIN_VALUE

Syntax:

absExact(arg)

For Example:

Math.absExact(-10) = > It return 10.

Approach

Java

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

        int a = -10;
        System.out.println(Math.absExact(a));

    }
}



No comments:

Post a Comment