×

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

How to Create a Package in Java?

For the most part, how to create a package in Java generally, a package is defined as a collection of relevant or irrelevant items together in a very major way....

7 minutes read.

Java Math nextAfter() Method

The nextAfter() method of Math class returns the floating-point value adjacent to the first argument in direction of the second argument. Syntax: public static double nextAfter (double start, double direction)public static float...

2 minutes read.

SHA Decrypt in Java

In this section, we will be acknowledged about the decryption of SHA in Java. Java SHA The SHA cryptographic hash algorithm in cryptography outputs the hash value as an approximately 40-digit-long hexadecimal...

4 minutes read.

New Features of Java 14

 Features like Switch expressions and text blocks which are previewed in Java 13 version are standardized in Java 14. Features in Java 14 Switch ExpressionText BlocksRecordsNull Pointer ExceptionsInstance ofPackaging ToolGarbage collectors 1.Switch Expressions Switch...

3 minutes read.

Applet Life Cycle in Java

In this article, we are going to acknowledge you about what a applet is, what is its life cycle and stages in life cycle, along with the syntax and example...

4 minutes read.

Group by in Java 8

By using this groupingBy() method, developers can directly able to perform the "GROUP BY" operation. The thing is, now, the Java 8 programming language allows the programmers to do this...

3 minutes read.

Properties Class in Java

Properties class is associated with Java since JDK 1.0, i.e. it is a legacy class. It is the subclass of Hashtable. It is used to maintain the lists of values in which...

5 minutes read.

Java Integer reverse() method

The reverse() method of Java Integer class returns the value obtained by reversing the order of the bits in the 2’s complement binary representation. Syntax public static int reverse (int i)  Parameters The parameter...

1 minute read.

Davis Staircase Problem in Java

Davis has several stairs in his home and prefers to ascend one, two, or three steps at a time. As a highly clever youngster, he thinks about how many ways...

3 minutes read.

Java Calculate Average of List

The list is a linear data structure used in Java to store ordered data collections. Additionally, it accepts duplicate values while maintaining insertion order. It is sometimes necessary to find...

3 minutes read.

Object Definition in Java

In this article, you will be acknowledged about object in Java, its definition and how is this useful in writing the programs in Java. The comprehension of object-oriented technology depends on...

4 minutes read.

How to sort an array in Java

Sorting is the process of arranging the elements of a list or array in a specific order, either ascending or descending. The sorting criterion numerical and alphabetical is commonly used...

6 minutes read.

MVC in Java

A well-known design pattern is Model-View-Controller. The discipline of web development. We can organize our code in this manner. The document stipulates that a program or application must include a...

4 minutes read.

Sliding Window Problem in Java

A sliding window is used in computer science and data science to process large datasets. It involves breaking the dataset into smaller chunks or windows and then processing it in...

6 minutes read.

How to add 24 Hours to Date in Java?

In this tutorial, we will learn how to add 24 hours to the local or current date in Java language. We will begin our topic with basic concepts and would...

2 minutes read.

Java Tokens

Classes and methods are included in the Java program. The procedures also provide the expressions and statements required to finish a specific operation. Tokens make up the sentences and expressions...

4 minutes read.

How to Round Double Float up to Two Decimal Places in Java

It indicates 15 digits just after the decimal place in Java whenever a double data type is used in front of a variable. For example, when representing rupees and other...

4 minutes read.

Java vs Node.js

Java: Java is an object oriented programming language. It is also known as multi threaded language. It was designed by James gosling in the year 1995. We can also say that...

4 minutes read.

Can Abstract Classes have Static Methods in Java

Abstract Class An abstract class in Java is one that explicitly uses the keyword "abstract" in its declaration. There are options for both non-abstract and abstract techniques (method with the body)....

4 minutes read.

Java md5 Hash Example

A 128-bit hash value is generated by the Message Digest Algorithm 5, which is a cryptographic algorithm. A stationary hash value is generated by the hash function from data of...

3 minutes read.