Java - StrictMath cos(double) 方法



描述

Java StrictMath cos(double a) 返回角度的三角餘弦。如果引數是 NaN 或無窮大,則結果為 NaN。計算結果必須在精確結果的 1 ulp 內。結果必須是半單調的。

宣告

以下是 java.lang.StrictMath.cos() 方法的宣告

public static double cos(double a)

引數

a − 要返回其三角餘弦的值。

返回值

此方法返回引數的三角餘弦。

異常

獲取角度的三角餘弦示例

以下示例演示了 StrictMath cos() 方法的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

      // get a variable x which is equal to PI/2
      double x = StrictMath.PI / 2;

      // convert x to radians
      x = StrictMath.toRadians(x);

      // get the arc sine of x
      System.out.println("StrictMath.cos(" + x + ")=" + StrictMath.cos(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

StrictMath.cos(0.027415567780803774)=0.9996242168594817

獲取 0° 角的三角餘弦示例

以下示例演示了 StrictMath cos() 方法在 0° 角上的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

      // get a variable x which is equal to zero
      double x = 0.0d;

      // convert x to radians
      x = StrictMath.toRadians(x);

      // get the arc sine of x
      System.out.println("StrictMath.cos(" + x + ")=" + StrictMath.cos(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

StrictMath.cos(0.0)=1.0

獲取 45° 角的三角餘弦示例

以下示例演示了 StrictMath cos() 方法在 45° 角上的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

      // get a variable x which is equal to zero
      double x = 45.0d;

      // convert x to radians
      x = StrictMath.toRadians(x);

      // get the arc sine of x
      System.out.println("StrictMath.cos(" + x + ")=" + StrictMath.cos(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

StrictMath.cos(0.7853981633974483)=0.7071067811865476
java_lang_strictmath.htm
廣告