Home >>Java Math Methods >Java Math.copySign() method
The java.lang. Math.copySign() in Java Math is used to return the second argument with the sign.
public static double copySign(double a, double b) public static float copySign(float a, float b)
a = This parameter is used the argument providing the magnitude of the result
b = This parameter is used the argument providing the sign of the result
This method is used to returns the magnitude of the first argument with the sign of the second argument.
public class MyClass
{
public static void main(String[] args)
{
double x = 120.8;
double y = -34.4;
System.out.println(Math.copySign(x, y));
}
}
public class MyClass
{
public static void main(String[] args)
{
double x = -123.03;
double y = 16.2;
System.out.println(Math.copySign(x, y));
}
}