當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java StrictMath cosh()用法及代碼示例


java.lang.StrictMath.cosh()是Java中的內置方法,該方法返回給定double參數的雙曲餘弦值。

  • 當參數為NaN時,該方法返回NaN。
  • 當參數為無窮大時,該方法返回正無窮大。
  • 當給定參數為0.0時,該方法返回1.0。

用法:

public static double cosh(double num)

參數:該方法接受一個雙精度類型的參數num,其雙曲餘弦值將被返回。


返回值:該方法返回num的雙曲餘弦值。

例子:

Input: num = 60.0
Output: 5.710036949078421E25

Input: num = 0.0
Output: 1.0

下麵的程序演示了java.lang.StrictMath.cosh()方法:
示例1:

// Java praogram to illustrate the 
// java.lang.StrictMath.cosh() 
import java.lang.*; 
  
public class Geeks { 
  
    public static void main(String[] args) 
    { 
  
        double num1 = 78.8, num2 = 0.0, num3 = 1.0; 
  
        // It returns the hyperbolic cosine of 
        // specified angle in radian 
        double coshvalue = StrictMath.cosh(num1); 
        System.out.println("The cosh of "+ 
                     num1+" = " + coshvalue); 
  
        coshvalue = StrictMath.cosh(num2); 
        System.out.println("The cosh of "+ 
                     num2+" = " + coshvalue); 
  
        coshvalue = StrictMath.cosh(num3); 
        System.out.println("The cosh of "+ 
                     num3+" = " + coshvalue); 
    } 
}
輸出:
The cosh of 78.8 = 8.344016962852523E33
The cosh of 0.0 = 1.0
The cosh of 1.0 = 1.543080634815244

示例2:

// Java praogram to illustrate the 
// java.lang.StrictMath.cosh() 
import java.lang.*; 
  
public class Geeks { 
  
    public static void main(String[] args) 
    { 
  
        double num1 = (30 * (Math.PI)) / 180; 
        double num2 = 11.0, num3 = 45.0; 
  
        // It returns the hyperbolic cosine of  
        // angle in radian 
        double coshvalue = StrictMath.cosh(num1); 
        System.out.println("The cosh of "+ 
                     num1+" = " + coshvalue); 
  
        coshvalue = StrictMath.cosh(num2); 
        System.out.println("The cosh of "+ 
                     num2+" = " + coshvalue); 
  
        coshvalue = StrictMath.cosh(num3); 
        System.out.println("The cosh of "+ 
                     num3+" = " + coshvalue);     
    } 
}
輸出:
The cosh of 0.5235987755982988 = 1.1402383210764286
The cosh of 11.0 = 29937.070865949758
The cosh of 45.0 = 1.7467135528742547E19


相關用法


注:本文由純淨天空篩選整理自ankita_chowrasia大神的英文原創作品 StrictMath cosh() Method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。