📜  Java toDegrees() 方法与示例

📅  最后修改于: 2022-05-13 01:54:25.328000             🧑  作者: Mango

Java toDegrees() 方法与示例

Java.lang.Math.toDegrees() 用于将以弧度测量的角度转换为以度为单位测量的近似等效角度。

注意:从弧度到度的转换通常是不精确的;用户不应期望 cos(toRadians(90.0)) 完全等于 0.0。

语法

public static double toDegrees(double rad)

Parameter:
rad : This parameter is an angle in radians which
we want to convert in degrees.
Return :
This method returns the measurement of the angle 
rad in degrees.

示例:显示Java.lang.Math.toDegrees()方法的工作。

// Java program to demonstrate working
// of java.lang.Math.toDegrees() method
import java.lang.Math;
  
class Gfg {
  
    // driver code
    public static void main(String args[])
    {
        // value of PI in degrees
        double rad = Math.PI;
        System.out.println(Math.toDegrees(rad));
  
        // value of PI/2 in degrees
        rad = (Math.PI) / 2;
        System.out.println(Math.toDegrees(rad));
  
        // value of PI/4 in degrees
        rad = (Math.PI) / 4;
        System.out.println(Math.toDegrees(rad));
    }
}

输出:

180.0
90.0
45.0