Java Math copySign() Method

The copySign() method of Math class returns the first floating-point argument with the sign of the second argument.

Syntax:

public static float copySign(float magnitude, float sign)

public static double copySign(double magnitude, double sign)

Parameters:

The parameter ‘magnitude’ and ‘sign’ represents the magnitude and sign of the result.

Return Value:

The copySign() method returns a value with the magnitude of magnitude and the sign of sign.

Example 1:

 Output:

Example 2:

 Output:

Example 3:

 Output:

Example 4:

 Output: