计算一个给定值的反正切


为了在 Java 中计算一个给定值的反正切,我们使用 java.lang.Math.atan() 方法。该方法接受一个双精度值,该值需要计算其角度。返回的角度范围位于 -pi/2 到 pi/2 之间。如果参数为 NaN,则结果为 NaN。

当参数为 0 时,输出为一个与参数具有相同符号的 0。

声明——java.lang.Math.atan() 方法的声明如下:

public static double atan(double a)

其中 a 是计算其反正切的值。

我们来看一个在 Java 中计算一个给定值的反正切的程序。

示例

import java.lang.Math;
public class Example {
   public static void main(String[] args) {
      // get two double numbers in degrees
      double x = Math.sqrt(3);
      double y = 1;
      // computing and displaying the arc tangent of these doubles
      System.out.println(“Arc tangent of " + x + " = " + Math.atan(x));
      System.out.println("Arc tangent of " + y + " = " + Math.atan(y));
   }
}

输出

Arc tangent of 1.7320508075688772 = 1.0471975511965976
Arc tangent of 1.0 = 0.7853981633974483

更新于: 26-Jun-2020

114 次浏览

开启您的 职业生涯

完成课程即可获得认证

开始
广告
© . All rights reserved.