Java教程

Java Math atan()

Java Math atan()

Java Math atan() 方法返回指定值的反正切。
反正切是切函数的反函数。
atan() 方法的语法是:
Math.atan(double num)
这里, atan() 是一个静态方法。因此,我们使用类名访问该方法, Math

atan() 参数

atan() 方法接受一个参数。
num-要返回其反正切函数的数字

atan() 返回值

返回指定数字的反正切 如果指定值为零则返回 0 如果指定的数字是NaN,则返回NaN
注意: 返回值是-pi/2 到 pi/2 之间的角度。

示例 1: Java Math atan()

import java.lang.Math;
class Main {
  public static void main(String[] args) {
    // create variable
    double a = 0.99;
    double b = 2.0;
    double c = 0.0;
    // print the arc tangent value
    System.out.println(Math.atan(a));  // 0.7803730800666359
    System.out.println(Math.atan(b));  // 1.1071487177940904
    System.out.println(Math.atan(c));  // 0.0
  }
}
在上面的例子中,我们导入了 java.lang.Math 包。如果我们想使用 Math 类的方法,这很重要。注意表达式,
Math.atan(a)
这里,我们直接使用了类名来调用方法。这是因为 atan() 是一个静态方法。

示例 2: Math atan() 返回 NaN

import java.lang.Math;
class Main {
  public static void main(String[] args) {
    // create variable
    // square root of negative number
    // results in not a number (NaN)
    double a = Math.sqrt(-5);
    // print the arc tangent  value
    System.out.println(Math.atan(a));  // NaN
  }
}
在这里,我们创建了一个名为 a 的变量。
Math.atan(a)-返回 NaN,因为负数(-5) 的平方根不是数字
注意: 我们使用了Java Math.sqrt() 计算数字平方根的方法。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4