Java StrictMath cosh()方法与示例
StrictMath类cosh()方法
cosh()方法在java.lang包中可用。
cosh()方法用于返回方法中给定参数角度的双曲余弦值。在此,“cosh”代表某个角度的双曲余弦。
cosh()方法是静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。
在此方法中,我们仅传递弧度类型的参数(即,首先,我们使用toRadians()StrictMath类的方法将给定的参数转换为弧度,然后在方法中传递相同的变量cosh())。
cosh()方法不会引发任何异常。
语法:
public static double cosh(double d);
参数:
doubled–表示要返回其角度的双曲余弦的值。
返回值:
此方法的返回类型为double-返回给定参数的双曲余弦值。
注意:
如果传递NaN,则该方法返回NaN。
如果我们传递无穷大(正数或负数),则该方法将返回相同的值。
如果传递零(正数或负数),则该方法返回1.0。
示例
//Java程序演示示例
//StrictMath类的cosh(doubled)方法的说明。
public class Cosh {
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("d1: " + d1);
System.out.println("d2: " + d2);
System.out.println("d3: " + d3);
System.out.println("d4: " + d4);
System.out.println("d5: " + d5);
//通过使用toRadians()方法转换
//绝对值转换成弧度。
d1 = StrictMath.toRadians(d1);
d2 = StrictMath.toRadians(d2);
d3 = StrictMath.toRadians(d3);
d4 = StrictMath.toRadians(d4);
d5 = StrictMath.toRadians(d5);
//在这里,我们将得到(infinity),因为我们是
//传递参数,其值为(infinity)
System.out.println("StrictMath.cosh(d1): " + StrictMath.cosh(d1));
//在这里,我们将得到(infinity),因为我们是
//传递参数,其值为(-infinity)
System.out.println("StrictMath.cosh(d2): " + StrictMath.cosh(d2));
//在这里,我们得到(1.0),因为我们
//传递参数,其值为(0.0)
System.out.println("StrictMath.cosh(d3): " + StrictMath.cosh(d3));
//在这里,我们得到(1.0),因为我们
//传递参数,其值为(-0.0)
System.out.println("StrictMath.cosh(d4): " + StrictMath.cosh(d4));
//找到d5的双曲余弦
//使用cosh()方法
System.out.println("StrictMath.cosh(d5): " + StrictMath.cosh(d5));
}
}输出结果
d1: Infinity d2: -Infinity d3: 0.0 d4: -0.0 d5: 60.0 StrictMath.cosh(d1): Infinity StrictMath.cosh(d2): Infinity StrictMath.cosh(d3): 1.0 StrictMath.cosh(d4): 1.0 StrictMath.cosh(d5): 1.600286857702386