Java.lang.StrictMath.cos() 方法
描述
java.lang.StrictMath.cos() 方法返回角度的三角余弦值。 这包括 −
如果参数为 NaN 或无穷大,则结果为 NaN。
声明
以下是 java.lang.StrictMath.cos() 方法的声明。
public static double cos(double a)
参数
a − 这是角度,以弧度为单位。
返回值
此方法返回参数的余弦。
异常
NA
示例
下面的例子展示了 java.lang.StrictMath.cos() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class StrictMathDemo {
public static void main(String[] args) {
double d1 = (60*(Math.PI))/180 , d2 = 0.0, d3 = (1.0/0.0) ;
// returns the trigonometric cosine of specified angle in radian
double cosValue = StrictMath.cos(d1);
System.out.println("Trigonometric cosine of d1 = " + cosValue);
cosValue = StrictMath.cos(d2);
System.out.println("Trigonometric cosine of d2 = " + cosValue);
cosValue = StrictMath.cos(d3);
System.out.println("Trigonometric cosine of d3 = " + cosValue);
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Trigonometric cosine of d1 = 0.5000000000000001 Trigonometric cosine of d2 = 1.0 Trigonometric cosine of d3 = NaN

