×

Java Math atan() Method

The atan() method of Math class computes the trigonometric Arc Tangent (inverse of tangent ) of an angle. The value returned is between -pi/2 to pi/2.

Syntax:

public static double atan(double a)

Parameters:

The parameter ‘a’ represents the value whose arc tangent is to be determined.

Return Value:

The atan() method returns the arc tangent of the argument .

  • It returns NaN, if we pass a NaN .
  • If we pass zero as an argument, it will return zero with the same sign as the argument.

Example 1:

public class JavaMathAtanExample1 {
    public static void main(String[] args) {
        double a=30;
        //return the arc tangent value for a
        System.out.println("Arc tangent value : "+Math.atan(a));
    }
}

Output:

Arc tangent value : 1.5374753309166493

Example 2:

public class JavaMathAtanExample2 {
    public static void main(String[] args) {
        //return the arc tangent value for Double.MIN_VALUE
        double a=Double.MIN_VALUE;
        System.out.println("Arc tangent value for "+a+" = "+Math.atan(a));
    }
}

Output:

Arc tangent value for 4.9E-324 = 4.9E-324

Example 3:

public class JavaMathAtanExample3 {
    public static void main(String[] args) {
        double x = Math.PI;
        System.out.println("Arc tangent value for "+x+" = "+Math.atan(x));
    }
}

Output:

Arc tangent value for 3.141592653589793 = 1.2626272556789115

Example 4:

public class JavaMathAtanExample4 {
    public static void main(String[] args) {
        //return an arc tangent value for infinity
        double x = 6/0.0d;
        System.out.println("Arc tangent value for "+x+" = "+Math.atan(x));
    }
}

Output:

Arc tangent value for Infinity = 1.5707963267948966

Example 5:

public class JavaMathAtanExample5 {
    public static void main(String[] args) {
        //return an arc tangent value for Nan
        double x = 0.0d/0.0d;
        System.out.println("Arc tangent value for "+x+" = "+Math.atan(x));
    }
}

Output:

Arc tangent value for NaN = NaN

Example 6:

public class JavaMathAtanExample6 {
    public static void main(String[] args) {
        //return an arc tangent value for negative Infinity
        double x = -90d/0.0d;
        System.out.println("Arc tangent value for "" = "+Math.atan(x));
    }
}

Output:

Arc tangent value for -Infinity = -1.5707963267948966

Related Topics

Java Keywords

Java Keywords The particular words which are used in java programming language that act like a key or important words to write a code are called java keywords. Java Keywords are...

4 minutes read.

Java Integer toString() method

The toString() method of Java Integer class returns a String object which represents this Integer’s value. The second syntax returns a String object which represents the specified integer. The third syntax returns...

2 minutes read.

How to create a mirror image of a 2D array in Java

Problem Statement We have provided a list of m x n. here m indicates rows, and n indicates columns). Printing the fresh matrices should result in a mirror reflection of an...

2 minutes read.

How to Convert Decimal to Binary in Java

How to Convert Decimal to Binary in Java There are two methods to convert Decimal to Binary. Using toBinaryString() method Using user-defined logic Using Integer.toBinaryString() The toBinaryString() is a static method of Integer...

2 minutes read.

How to check Date Null in Java?

In this section, we will be acknowledged about Date Null in Java. The date null in Java is an entity that is used when there is no specified value for...

3 minutes read.

Difference Between Data Hiding and Abstraction in Java

Abstraction: Data Abstraction and Data Hiding ideas are utilised to show the expected data to the end client and conceal the superfluous subtleties, however, for specific purposes like decreasing the framework's...

10 minutes read.

Java String Matches vs Contains

String Matches in Java The matches() function and its variations are used to determine whether or not a provided text matches a regular expression. The functioning as well as output of...

3 minutes read.

Java Boyer Moore

A string searching or matching technique called the Boyer-Moore algorithm was created in 1977 by Robert S. Boyer and J. Strother Moore. It is the most popular and effective string-matching...

9 minutes read.

Print Matrix Diagonally in Java

The aim is to print the elements of a matrix of size n*n in some kind of a diagonal pattern. Input : mat[3][3] = {{1, 2, 3},                      {4, 5, 6},                      {7,...

3 minutes read.

Collection Interfaces in Java with Examples

In this tutorial, we will discuss collection interfaces in Java with Examples. Introduction The Collection Interface is an individual from the Java Collections Framework. It is a root point of interaction of...

4 minutes read.

Inheritance Program in Java

Inheritance Program in Java Inheritance is one of the important pillars of Object-Oriented Programming that facilitates parent-child relationships in programming. Using inheritance, we can create a new class with the help...

7 minutes read.

Arrow Operator in Java

The introduction of arrow functions in ES6 gives you a more precise approach to define JavaScript functions. We can write shorter function syntax thanks to them. Your code will be...

4 minutes read.

Java Boolean logicalOr() Method

The logicalOr() method of Java Boolean class returns the result of implementing logical OR operation on the specified Boolean operands. Syntax: public static boolean logicalOr (boolean a, boolean b) Parameters: The parameters ‘a’ and...

2 minutes read.

Sorting Algorithms in Java

Sorting Algorithms in Java Sorting is the technique that puts the elements of an array or list either in descending or ascending order. For example, take an array A, whose elements...

3 minutes read.

Packages in Java

Packages in Java can be defined as an assortment for grouping various classes and interfaces based on their performance. It is a catalog for holding various java files. They provide...

4 minutes read.

Hello Program in Java

Hello Program in Java The Hello program in Java displays the word Hello on the console. It is the basic program in Java. In this section, we will learn different ways...

3 minutes read.

Bedrock vs Java

The popularity of Minecraft, a sandbox video game, has skyrocketed. The scope, level of complexity, and variety of gameplay in this game are enormous, and user-generated content has helped to...

4 minutes read.

Java TreeMap

TreeMap in Java with Example Java TreeMap implements the NavigableMap interface. It extends Map Interface. Java TreeMap is based on the red-black Tree implementation. It stores the key-value pair in sorted...

7 minutes read.

Equilibrium Index of an Array in Java

An array's equilibrium index is the condition where the sum of items with lower and higher indices equals. For example, an array A=[-4,5 2,6,-5] where: a[0]=-4, a[1]=5, a[2]=2, a[3]=6, a[4]=-5 Now according...

4 minutes read.

Java List Implementations

ArrayList and LinkedList are the two implementations of List that are for general-purpose. You'll probably utilise an array list the majority of the time because it's quick and provides constant-time...

3 minutes read.