Java Math.copySign(double magnitude, double sign)

Syntax

Math.copySign(double magnitude, double sign) has the following syntax.

public static double copySign(double magnitude,  double sign)

Example

In the following code shows how to use Math.copySign(double magnitude, double sign) method.


public class Main {
/* w  w w .  j  av a 2s.co  m*/
   public static void main(String[] args) {

      double x = 125.9;
      double y = -0.4873;

      System.out.println(Math.copySign(x, y));
      System.out.println(Math.copySign(y, x));

   }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable