Java Tutorial Java Advanced Java References

Java Math - atan() Method



The Java atan() method returns arc tangent of a value. The returned value will be in the range -𝜋/2 through 𝜋/2. In special cases it returns the following:

  • If the argument is NaN, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Note: atan() is the inverse of tan().

Syntax

public static double atan(double arg)

Parameters

arg Specify the value.

Return Value

Returns the arc tangent of the value.

Exception

NA.

Example:

In the example below, atan() method is used to find out the arc tangent of a given value.

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.atan(0.5));   
  System.out.println(Math.atan(1));
  System.out.println(Math.atan(2));     
 }
}

The output of the above code will be:

0.4636476090008061
0.7853981633974483
1.1071487177940904

❮ Java Math Methods