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

Tutorial Básico de Java

Controle de fluxo do Java

Array do Java

Java orientado a objetos (I)

Java orientado a objetos (II)

Java orientado a objetos (III)

Tratamento de Exceção Java

Java Lista (List)

Java Queue (fila)

Conjunto Map do Java

Conjunto Set do Java

E/S do Java (I/O)

Reader do Java/Writer

Outros tópicos do Java

Uso e exemplo do Math.atan() do Java

Java Math Mathematical Methods

O método Math.atan() do Java retorna o valor arco tangente do número especificado.

A tangente inversa é a função inversa da tangente.

A sintaxe do método atan() é:

Math.atan(double num)

Parâmetro atan()

  • num - O número a retornar a função arco tangente

O valor de retorno do atan()

  • Retorna o arco tangente do número especificado

  • Se o valor especificado for zero, retorna 0

  • Se o valor especificado for NaN, retorna NaN

NoteA função de retorno é -pi / 2 até pi / 2 entre os ângulos.

Example1Java matemática 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)

Here, we used the class name directly to call the method. 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
  }
}

Here, we created a variable named a.

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

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

Java Math Mathematical Methods