Java StrictMath.copySign(float magnitude, float sign)

Syntax

StrictMath.copySign(float magnitude, float sign) has the following syntax.

public static float copySign(float magnitude,  float sign)

Example

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


public class Main {
/*www  .  j  a v  a 2s. c o m*/
  public static void main(String[] args) {
  
    float f1 = 3 , f2 = -1, f3 = 1 , f4 = -14;
     
    System.out.println("value of f1 with sign f2 : " + StrictMath.copySign(f1 , f2));
     
    System.out.println("value of f1 with sign f3 : " + StrictMath.copySign(f1 , f3));
     
    System.out.println("value of f2 with sign f4 : " + StrictMath.copySign(f2 , f4));
  }
}

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