Abs() Double in Java

double java.lang.Math.abs(double a) 

abs(): This function returns the absolute value of a double value.If the argument is not negative, the argument is returned.If the argument is negative, the negation of theargument is returned.

Special cases: 

1.If the argument is positive zero or negative zero, the result is positive zero.

2.If the argument is infinite, the result is positive infinity.

3.If the argument is NaN, the result is NaN.

Parameters: One argument is required for this function.

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

Returns: the absolute value of the argument.

Syntax:

Math.abs(arg)

For Example:

Math.abs(-12.45) = > It return 12.45

Approach

Java


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

        double num = -12.45;
        System.out.println(Math.abs(num));

    }


No comments:

Post a Comment