StrictMath.abs(float) in Java

StrictMath.abs(float): This method is available in java.lang.StrictMath class of Java.

Syntax:

float java.lang.StrictMath.abs(float a)

This method takes one argument of type float as its parameter. This method returns the absolute value of a float value.

Note:

1. If the argument is not negative, the argument is returned.

2. If the argument is negative, the negation of the argument 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 parameter is required for this method.

a: the argument whose absolute value is to be determined.

Returns: the absolute value of the argument.

Exceptions: NA

Approach

Java

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

        float a = -178.89f;
        System.out.println(StrictMath.abs(a));
    }
}

Output:

178.89


No comments:

Post a Comment