此方法在java.lang包中可用。
此方法用于返回方法中给定参数的角度的三角余弦。
在此方法中,cos代表角度的余弦。
这是一个静态方法,因此也可以使用类名访问此方法。
此方法的返回类型是double,这意味着它将返回给定角度的余弦值,并且该值是double类型。
在此方法中,我们仅将一个参数作为参数传递给Math类的方法,并且给定参数是那些我们必须找到角度的余弦值的参数。
在此方法中,我们仅传递弧度类型的参数(即,首先,通过使用toRadians()Math类的方法将给定的参数转换为弧度,然后在方法中传递相同的变量cos())。
此方法不会引发任何异常。
语法:
public static double cos(double d){
}参数:
double d –一个要找到其余弦值的双精度值(角度)。
注意:
如果我们传递“ NaN”,则返回“ NaN”。
如果传递无穷大,则返回“ NaN”。
返回值:
此方法的返回类型为double,它返回给定角度的余弦值。
//Java程序演示cos(double d)的示例
//数学课的方法
class CosMethod {
public static void main(String[] args) {
//在这里,我们声明了几个变量
double d1 = 7.0 / 0.0;
double d2 = -7.0 / 0.0;
double d3 = 60.0;
//显示d1,d2和d3的先前值
System.out.println(" Before implementing cos() so the value of d1 is :" + d1);
System.out.println(" Before implementing cos() so the value of d2 is :" + d2);
System.out.println(" Before implementing cos() so the value of d3 is :" + d3);
//通过使用toRadians()方法转换
//绝对值转换成弧度
d1 = Math.toRadians(d1);
d2 = Math.toRadians(d2);
d3 = Math.toRadians(d3);
//在这里,我们得到(NaN),因为我们通过
//值为(infinity)
System.out.println("After implementing cos() so the value of d1 is :" + Math.cos(d1));
//在这里,我们得到(NaN),因为我们通过
//值是(-infinity)
System.out.println("After implementing cos() so the value of d2 is :" + Math.cos(d2));
//找到d3的余弦值
System.out.println("After implementing cos() so the value of d3 is :" + Math.cos(d3));
}
}输出结果
E:\Programs>javac AtanMethod.java E:\Programs>java AtanMethod Before implementing cos() so the value of d1 is :Infinity Before implementing cos() so the value of d2 is :-Infinity Before implementing cos() so the value of d3 is :60.0 After implementing cos() so the value of d1 is :NaN After implementing cos() so the value of d2 is :NaN After implementing cos() so the value of d3 is :0.5000000000000001