Java StrictMath.copySign(double magnitude, double sign)

Syntax

StrictMath.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 StrictMath.copySign(double magnitude, double sign) method.


//from w  w w. j  av a  2s . c  o m
public class Main {

  public static void main(String[] args) {
  
    double d1 = 1.2 , d2 = -1.2, d3 = 1.3 , d4 = -14;

    System.out.println("value of d1 with sign d2 : " + StrictMath.copySign(d1, d2));
    
    System.out.println("value of d1 with sign d3 : " + StrictMath.copySign(d1, d3));
    
    System.out.println("value of d2 with sign d4 : " + StrictMath.copySign(d2, d4));
  }
}

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