English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math mathematical methods
La méthode Java Math copySign() copie le signe du deuxième paramètre et l'attribue au premier paramètre.
La syntaxe de la méthode copySign() est :
Math.copySign(arg1, arg2)
Note:La méthode copySign() est une méthode statique. Par conséquent, nous pouvons appeler cette méthode directement en utilisant le nom de la classe Math.
arg1 - Le premier paramètre à remplacer par son symbole
arg2 - Le deuxième paramètre, dont le symbole est copié dans arg1
notemeaning: data type arg1and arg2should be float or double.
returns the first parameter, arg1with the second parameter arg2the sign
Note: for the parameter(arg1,-arg2), this method returns-arg1.
class Main { public static void main(String[] args) { // Copy the sign of the double parameter double x = 9.6d; double y = -6.45; System.out.println(Math.copySign(x, y)); // -9.6 // Copy the sign of the float parameter float a = -4.5f; float b = 7.34f; System.out.println(Math.copySign(a, b)); // 4.5 } }
As you can see, here the copySign() method assigns the sign of the second variable (y and b) is assigned to the first variable (x and a)