Java - Math toRadians(double x) 方法



描述

Java Math toRadians(double angdeg) 方法將以度為單位測量的角度轉換為近似等效的以弧度為單位測量的角度。度到弧度的轉換通常是不精確的。

宣告

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

public static double toRadians(double angdeg)

引數

angdeg − 以度為單位的角度

返回值

此方法返回以弧度表示的角度 angdeg 的度量。

異常

從正雙精度值獲取弧度示例

以下示例演示了對正雙精度值使用 Math toRadians() 方法。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = 45.0;

      // print the radian for this double
      System.out.println("Math.toRadians(" + x + ")=" + Math.toRadians(x));
   }
}

輸出

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

Math.toRadians(45.0)=0.7853981633974483

從負雙精度值獲取弧度示例

以下示例演示了使用 Math toRadians() 方法獲取負雙精度值的弧度。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = -45.0;

      // print the radian for this double
      System.out.println("Math.toRadians(" + x + ")=" + Math.toRadians(x));
   }
}

輸出

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

Math.toRadians(-45.0)=-0.7853981633974483

從零雙精度值獲取弧度示例

以下示例演示了使用 Math toRadians() 方法獲取零雙精度值的弧度。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = 0.0;

      // print the radian for this double
      System.out.println("Math.toRadians(" + x + ")=" + Math.toRadians(x));
   }
}

輸出

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

Math.toRadians(0.0)=0.0
java_lang_math.htm
廣告
© . All rights reserved.