Java.lang.Math.cos() 方法
描述
java.lang.Math.cos(double a)返回角度的三角余弦值。如果参数是NaN或无穷大,则结果为NaN。计算结果必须在1 ulp以内 的确切结果。 结果必须是半单调的。
声明
以下是 java.lang.Math.copySign() 方法的声明。
public static double cos(double a)
参数
a − 角度,单位为弧度
返回值
此方法返回参数的余弦。
异常
NA
示例
下面的例子展示了 lang.Math.cos() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class MathDemo {
public static void main(String[] args) {
// get two double numbers
double x = 45.0;
double y = 180.0;
// convert them to radians
x = Math.toRadians(x);
y = Math.toRadians(y);
// print their cosine
System.out.println("Math.cos(" + x + ")=" + Math.cos(x));
System.out.println("Math.cos(" + y + ")=" + Math.cos(y));
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Math.cos(0.7853981633974483)=0.7071067811865476 Math.cos(3.141592653589793)=-1.0

