Abs() float in Java

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

abs(): This function returns the absolute value of a float value. If the argument is not negative, the argument is returned. 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 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.0) = > It returns 12

Approach

Java

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

        float num = (float) -12.0;

        System.out.println(Math.abs(num));

    }
}


No comments:

Post a Comment