StrictMath.copySign(float, float) in Java

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

Syntax:

float java.lang.StrictMath.copySign(float magnitude, float sign)

This method takes two arguments of type float as its parameters. This method returns the first floating-point argument with the sign of the second floating-point argument.

Parameters: Two parameters are required for this method.

magnitude: the parameter providing the magnitude of the result.

sign: the parameter providing the sign of the result.

Returns: a value with the magnitude of magnitude and the sign of a sign.

Exceptions: NA

Approach

Java

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

        float magnitude = 124.0f;
        float sign = -1;
        System.out.println(StrictMath.copySign(magnitude, sign));
    }
}

Output:

-124.0


No comments:

Post a Comment