Java - Math acos(double) 方法



描述

Java Math acos(double a) 方法返回一個角度的反餘弦值,範圍在 0.0 到 pi 之間。如果引數是 NaN 或其絕對值大於 1,則結果為 NaN。結果必須在正確舍入結果的 1 ulp 內。結果必須是半單調的。

宣告

以下是 java.lang.Math.acos() 方法的宣告

public static double acos(double a)

引數

a − 要返回其反餘弦的值。

返回值

此方法返回引數的反餘弦。

異常

獲取角度的反餘弦示例

以下示例顯示了 Math acos() 方法的使用。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

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

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

      // get the arc cosine of x
      System.out.println("Math.acos(" + x + ")=" + Math.acos(x));
   }
}

輸出

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

Math.acos(0.027415567780803774)=1.5433773235341761

獲取 0° 角的反餘弦示例

以下示例顯示了 Math acos() 方法在 0° 角上的使用。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

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

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

      // get the arc cosine of x
      System.out.println("Math.acos(" + x + ")=" + Math.acos(x));
   }
}

輸出

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

Math.acos(0.0)=1.5707963267948966

獲取 45° 角的反餘弦示例

以下示例顯示了 Math acos() 方法在 45° 角上的使用。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

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

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

      // get the arc cosine of x
      System.out.println("Math.acos(" + x + ")=" + Math.acos(x));
   }
}

輸出

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

Math.acos(0.7853981633974483)=0.6674572160283838
java_lang_math.htm
廣告

© . All rights reserved.