StrictMath.copySign(double, double): This method is available in java.lang.StrictMath class of Java.
Syntax:
double java.lang.StrictMath.copySign(double magnitude, double sign)
This method takes two arguments of type double as its parameter. This method returns the first floating-point argument with the sign of the second floating-point argument. For this method, a NaN sign argument is always treated as if it were positive.
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 StrictMathcopySigndouble {public static void main(String[] args) {double magnitude = 124;double sign = -1;System.out.println(StrictMath.copySign(magnitude, sign));}}
Output:
-124.0
No comments:
Post a Comment