在 Java 中獲取給定值的雙曲正切
為了在 Java 中獲取給定值的雙曲正切,我們使用 java.lang.Math.tanh() 方法。tanh() 方法接受以弧度為單位的引數,並返回引數作為角度時的雙曲正切。
宣告 −java.lang.Math.tanh() 宣告如下 −
public static double tanh(double x)
其中,x 為弧度為單位的角度。
我們看一個 Java 程式,用它來獲取給定值的雙曲正切。
示例
import java.lang.Math; public class Example { public static void main(String[] args) { // get two double numbers in degrees double x = 90; double y = 180; // convert them in radians x = Math.toRadians(x); y = Math.toRadians(y); // computing and displaying the hyperbolic tangent of these doubles System.out.println("Hyperbolic tangent of " + x + " = " + Math.tanh(x)); System.out.println("Hyperbolic tangent of " + y + " = " + Math.tanh(y)); } }
輸出
Hyperbolic tangent of 1.5707963267948966 = 0.9171523356672744 Hyperbolic tangent of 3.141592653589793 = 0.99627207622075
廣告