# Java atan Function

The Java atan function is one of the Java Math functions, which is to calculate the trigonometry Arc Tangent for the specified expression. Arc Tangent also called the inverse of a Tangent.

## Java atan Function Syntax

The basic syntax of the Math.atan2 in Java Programming language is as shown below.

```static double atan(double y, double x); //Return Type is Double

// In order to use in program:
Math.atan2(double y, double x);```

Number: It can be a double value or a valid numerical expression for which you want to find Arc Tangent value.

• If the number argument is a positive or negative number, the Java Math.atan function will return the Arc Cosine value.
• If the number argument is Not a number, the Math.atan function will return NaN.

## Java atan Function Example

The Java Math.atan Function finds the trigonometric Arc Tangent of the double values.

In this Java program, We are going to find the Arc Tangent values of both positive and negative values and display the output.

```package TrigonometricFunctions;

public class AtanMethod {
public static void main(String[] args) {
double x = Math.atan(14.56 - 30.65 + 26.44);
System.out.println("Arc Tangent value =  " + x);

System.out.println("\nArc Tangent value of Positive Value = " + Math.atan(10.65));
System.out.println("Arc Tangent value of Positive Value =  " + Math.atan(15.58));

System.out.println("\nArc Tangent value of Negative Value =  " + Math.atan(-90.75));
System.out.println("Arc Tangent value of Negative Value =  " + Math.atan(-12.50));

System.out.println("\nArc Tangent value of Radiant Value = " + Math.atan(m));
}
}```

Within this Java atan function example, we used the Java Math.atan function directly on expression. Here, we used System.out.println statement to print the Arc Tangent result as output.

```double x = Math.atan(14.56 - 30.65 + 26.44);
System.out.println("Arc Tangent value =  " + x);```

Next, we used the atan Math function directly on Positive double values. Please refer to the Java tan Function to understand the Tangent Function.

```System.out.println("\nArc Tangent value of Positive Value = " + Math.atan(10.65));
System.out.println("Arc Tangent value of Positive Value =  " + Math.atan(15.58));```

Here, we used the Java Math.atan Function directly on Negative double values.

```System.out.println("\nArc Tangent value of Negative Value =  " + Math.atan(-90.75));
System.out.println("Arc Tangent value of Negative Value =  " + Math.atan(-12.50));```

Next, we declared a variable of type Double and assigned the value. Here, we used the Math.toRadians function to convert 90 into equivalent radiant. Then the System.out.println statement to print the result as output.

```double m = Math.toRadians(90);
System.out.println("\nArc Tangent value of Radiant Value = " + Math.atan(m));```

## Java atan on Array example

In this Java program, we will show how to find the Arctangent values of bulk data. Here, we are going to declare an array of double type and find the arctangent values of array elements.

```package TrigonometricFunctions;

public class AtanMethodOnArrays {
public static void main(String[] args) {

double [] myArray = {0, 1, 30, 45, 60, 75, 90, 120, 180, 240, 360};

for (int i = 0; i < myArray.length; i++) {
System.out.format("Arc Tangent of Array Element %.2f is = %.4f\n", myArray[i], Math.atan(myArray[i]));
}
}
}```
``````Arc Tangent of Array Element 0.00 is = 0.0000
Arc Tangent of Array Element 1.00 is = 0.7854
Arc Tangent of Array Element 30.00 is = 1.5375
Arc Tangent of Array Element 45.00 is = 1.5486
Arc Tangent of Array Element 60.00 is = 1.5541
Arc Tangent of Array Element 75.00 is = 1.5575
Arc Tangent of Array Element 90.00 is = 1.5597
Arc Tangent of Array Element 120.00 is = 1.5625
Arc Tangent of Array Element 180.00 is = 1.5652
Arc Tangent of Array Element 240.00 is = 1.5666
Arc Tangent of Array Element 360.00 is = 1.5680``````

We used the Java For Loop to iterate the Array. Within the atan For Loop, we initialized the i value as 0. Next, the Jcompiler will check for the condition (i < myArray.length). The Java myArray.length finds the length of an array,

`for (int i = 0; i < myArray.length; i++) {`

Here, we used the Java atan Function directly inside the System.out.format statement. The compiler will call the Math.atan method ( static double atan(double number)) to find the corresponding Arc Tangent values and print the output.

`System.out.format("Arc Tangent of Array Element %.2f is = %.4f\n", myArray[i], Math.atan(myArray[i]));`

NOTE: To find the Arc Tangent value of a single item, then use: Math.atan(myArray[index_position])

## Java atan Function on Arraylist example

In this Java program, we are going to declare an ArrayList of double type and find the Arctangent values of list elements.

```package TrigonometricFunctions;

import java.util.ArrayList;

public class AtanMethodOnArrayList {
public static void main(String[] args) {
ArrayList<Double> myList = new ArrayList<Double>(5);

for (double x : myList) {
System.out.format("Arc Tangent value of ArrayList Item %.2f =  %.4f \n", x, Math.atan(x));
}
}
}```
``````Arc Tangent value of ArrayList Item 3.14 =  1.2626
Arc Tangent value of ArrayList Item 1.05 =  0.8084
Arc Tangent value of ArrayList Item 0.79 =  0.6658
Arc Tangent value of ArrayList Item 0.52 =  0.4823
Arc Tangent value of ArrayList Item 0.35 =  0.3358
Arc Tangent value of ArrayList Item 0.26 =  0.2561
Arc Tangent value of ArrayList Item 0.20 =  0.1939``````

First, We declared an ArrayList of double type and assigned some random values using Math.PI constant (its value is approximately 3.14)

```ArrayList<Double> myList = new ArrayList<Double>(5);
`for (double x : myList) {`
`System.out.format("Arc Tangent value of ArrayList Item %.2f =  %.4f \n", x, Math.atan(x));`