此方法在java.lang包中可用。
在这种方法中,cosh代表某个角度的双曲余弦。
此方法用于返回给定参数角度的双曲余弦值。
这是一个静态方法,因此也可以使用类名进行访问。
此方法的返回类型为double,这意味着它将返回给定参数的双曲余弦值。
在此方法中,我们仅传递一个双精度类型参数作为参数(以弧度表示),其双曲余弦值将被返回。
此方法不会引发任何异常。
语法:
public static double cosh(double d){
}参数:双精度型参数作为参数(以弧度表示),将返回其双曲余弦值。
返回值:
此方法的返回类型为double,它返回某个角度的双曲余弦值。
注意:
如果我们传递“ NaN”,则返回“ NaN”。
如果我们传递带有任何符号(正数或负数)的无穷大,它将返回相同的值。
如果传递零(-0或0),则返回1.0。
//Java程序演示的例子
//数学类的cosh(double d)方法
class CoshMethod {
public static void main(String[] args) {
//在这里,我们声明了几个变量
double d1 = 7.0 / 0.0;
double d2 = -7.0 / 0.0;
double d3 = 0.0;
double d4 = -0.0;
double d5 = 60.0;
//显示d1,d2,d3,d4和d5的先前值
System.out.println(" Before implementing cosh() so the value of d1 is : " + d1);
System.out.println(" Before implementing cosh() so the value of d2 is : " + d2);
System.out.println(" Before implementing cosh() so the value of d3 is : " + d3);
System.out.println(" Before implementing cosh() so the value of d4 is : " + d4);
System.out.println(" Before implementing cosh() so the value of d5 is : " + d5);
//通过使用toRadians()方法将绝对值转换为弧度。
d1 = Math.toRadians(d1);
d2 = Math.toRadians(d2);
d3 = Math.toRadians(d3);
d4 = Math.toRadians(d4);
d5 = Math.toRadians(d5);
//在这里,我们将得到(infinity),因为我们是
//传递参数,其值为(infinity)
System.out.println("After implementing cos() so the value of d1 is : " + Math.cosh(d1));
//在这里,我们将得到(infinity),因为我们是
//传递参数,其值为(-infinity)
System.out.println("After implementing cosh() so the value of d2 is : " + Math.cosh(d2));
//在这里,我们将得到(1.0),因为我们正在传递参数
//其值为(0.0)
System.out.println("After implementing cosh() so the value of d3 is : " + Math.cosh(d3));
//在这里,我们将得到(1.0),因为我们正在传递参数
//其值为(-0.0)
System.out.println("After implementing cosh() so the value of d4 is : " + Math.cosh(d4));
//找到d5的双曲余弦值
System.out.println("After implementing cosh() so the value of d5 is : " + Math.cosh(d5));
}
}输出结果
E:\Programs>javac CoshMethod.java E:\Programs>java CoshMethod Before implementing cosh() so the value of d1 is : Infinity Before implementing cosh() so the value of d2 is : -Infinity Before implementing cosh() so the value of d3 is : 0.0 Before implementing cosh() so the value of d4 is : -0.0 Before implementing cosh() so the value of d5 is : 60.0 After implementing cos() so the value of d1 is : Infinity After implementing cosh() so the value of d2 is : Infinity After implementing cosh() so the value of d3 is : 1.0 After implementing cosh() so the value of d4 is : 1.0 After implementing cosh() so the value of d5 is : 1.600286857702386