Java toRadians() 方法示例

java 8object oriented programmingprogramming更新于 2025/12/9 23:08:17

java.lang.Math.toRadians(double angdeg) 方法将以度为单位的角度转换为以弧度为单位的近似等效角度。从度到弧度的转换通常不精确。

示例

此处,angdeg 方法返回一个以度为单位的角度。现在我们来看一个 − 的示例。

import java.lang.*;
public class MathDemo {
   public static void main(String[] args) {
      // 获取两个 double 类型的数字
      double x = 45;
      double y = -180;
      // 将它们转换为弧度
      x = Math.toRadians(x);
      y = Math.toRadians(y);
      // 打印这些双精度数的双曲正切值
      System.out.println("Math.tanh(" + x + ")=" + Math.tanh(x));
      System.out.println("Math.tanh(" + y + ")=" + Math.tanh(y));
   }
}

输出

Math.tanh(0.7853981633974483)=0.6557942026326724
Math.tanh(-3.141592653589793)=-0.99627207622075

示例

让我们看另一个例子 −

import java.lang.*;
public class MathDemo {
   public static void main(String[] args) {
      double x = 90.0;
      double y = 30.0;
      // 将它们转换为弧度
      x = Math.toRadians(x);
      y = Math.toRadians(y);
      // 打印这些双精度数的双曲正切值
      System.out.println("Math.tanh(" + x + ")=" + Math.tanh(x));
      System.out.println("Math.tanh(" + y + ")=" + Math.tanh(y));
   }
}

输出

Math.tanh(1.5707963267948966)=0.9171523356672744
Math.tanh(0.5235987755982988)=0.4804727781564516

相关文章