Java.lang.StrictMath 类

java.lang.StrictMath.cos() 方法返回角度的三角余弦(角度应以弧度为单位)。在特殊情况下,它返回以下内容:

  • 如果参数为 NaN 或无穷大,则结果为 NaN。

在下图中,<绘制了 i>cos(x) 与 x 的关系。

Cos Function

语法

public static double cos(double a)

参数

a 以弧度指定角度。

返回值

返回参数的三角余弦。

例外

不适用。

示例:

在下面的示例中,使用 cos() 方法求三角余弦给定角度。

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(StrictMath.cos(StrictMath.PI/6));   
  System.out.println(StrictMath.cos(StrictMath.PI/4));
  System.out.println(StrictMath.cos(StrictMath.PI/3));      
 }
}

上述代码的输出将是:

0.8660254037844387
0.7071067811865476
0.5000000000000001