English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutoriel de base Java

Java 流程控制

Java 数组

Java 面向对象(I)

Java 面向对象(II)

Java 面向对象(III)

Gestion des exceptions Java

Java 列表(List)

Java Queue(队列)

Java Map集合

Java Set集合

Java 输入输出(I/O)

Java Reader/Writer

Java 其他主题

Java Math atan() 使用方法及示例

Java Math mathematical methods

Java Math atan()方法返回指定值的反正切值。

反正切线是正切函数的反函数。

atan()方法的语法为:

Math.atan(double num)

atan()参数

  • num - 要返回其反正切函数的数字

atan()返回值

  • 返回指定数字的反正切

  • 如果指定值为零,则返回0

  • 如果指定的数量是NaN,返回NaN

Note:返回值是 -pi / 2 到 pi / 2 之间的角度。

Example1:Java数学atan()

import java.lang.Math;
class Main {
  public static void main(String[] args) {
    //Create a variable
    double a = 0.99;
    double b = 2.0;
    double c = 0.0;
    //Print the arctangent 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
  }
}

In the above example, we have imported the java.lang.Math package. This is important if we want to use the methods of the Math class. Note the expression

Math.atan(a)

In this case, we used the class name to call the method directly. This is because atan() is a static method.

Example2: Math.atan() returns NaN

import java.lang.Math;
class Main {
  public static void main(String[] args) {
        //Create a variable
        //Square root of a negative number
        //The result is not a number (NaN)
    double a = Math.sqrt(-5);
    //Print the arctangent value
    System.out.println(Math.atan(a));  // NaN
  }
}

In this case, we have created a variable named a.

  • Math.atan(a) - Returns NaN because a negative number (-5) is not a number

Note:We have already usedJava Math sqrt()method to calculate the square root of a number.

Java Math mathematical methods