目录

static double cos(double a)

描述 (Description)

java.lang.StrictMath.cos()方法返回角度的三角余弦值。 它包括 -

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

声明 (Declaration)

以下是java.lang.StrictMath.cos()方法的声明

public static double cos(double a)

参数 (Parameters)

a - 这是角度,以弧度表示。

返回值 (Return Value)

此方法返回参数的余弦值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.StrictMath.cos()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018