×

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 Integer signum() method

The signum() method of Java Integer class returns the signum function of the specified int value. Syntax public static int signum (int i)  Parameters The parameter ‘i’ represents the value whose signum is to...

1 minute read.

How many ways to create object in Java?

In this article, you will be acknowledged about the different ways to create an object in java. So far you construct an object from a class, as is common knowledge,...

6 minutes read.

Relatively Prime in Java

In this article, you will be very well equipped with a knowledge of a relatively prime number and also Java programs to determine whether a given integer is a relatively...

4 minutes read.

Set Matrix Zeros in Java

In coding round interviews, it is frequently asked as the most significant challenge. an m*n matrix is provided. Set the entire column and row of the matrix to 0 if any...

6 minutes read.

Java RandomAccessfile

Writing and reading to random access files are done using this class. An array of many bytes is how a random access file operates. By changing the implied file pointer...

3 minutes read.

Java Math getExponent() Method

The getExponent() method of Math class returns the unbiased exponent of the argument. Syntax: public static int getExponent (double d) Parameters: The parameter ‘d’ represents the double value. Return Value: The getExponent () method returns the...

1 minute read.

Java Maven Silicon

Maven is a build automation tool that is mostly used for Java applications. It allows you to manage the build, reporting, and documentation of a project from the central location. Maven provides...

4 minutes read.

Heart Pattern in Java

Heart Pattern is yet another intricate pattern program, however, due to its complexity, interviewers hardly ever inquire about it. Method for Printing the Heart Number Pattern Put the value of the total row...

2 minutes read.

Default Virtual Behaviour in C++ vs Java

Virtual Behaviour in C++: The class member methods in C++ are, by default, non-virtual. This implies that by simply defining it, they can be turned into virtual. The virtual class can be...

3 minutes read.

How to declare string array in Java

Introduction Array is a data structure with a fixed size, which allows us to store elements of similar type. Data of primitive types like int, char, float, string, etc. can be...

2 minutes read.

Java URL Class with Example

Java URL Uniform Resource Locator To find any resource on the internet, you need to have an address of it. The URL and IP addresses are the pointers used for this purpose....

12 minutes read.

Java ArrayList

Java ArrayList Class A Java ArrayList class is a dynamic array which is used to store the elements. It is a part of collection framework. It implements the List Interface and inherits the...

12 minutes read.

What is string in Java why it's immutable

String in Java Strings are a series of characters commonly used in Java language, which are considered objects in the Java. To create and manipulate strings, java will provide the String...

4 minutes read.

Java HashMap

Java HashMap extends AbstractMap and implements Map interface. It is the collection of multiple entries where an entry consists of key and value pair. The HashMap can contain only one...

7 minutes read.

Libraries in Java

The Java Class Library (JCL) specifically is a set of dynamically loadable libraries that Java Virtual Machine (JVM) languages can call at any run time, which is fairly significant because...

6 minutes read.

Camel Case in Java

Java names its classes, interfaces, methods, as well as variables using camel-case syntax. If the name consists of two words, the second word will always begin with a capital letter,...

3 minutes read.

Memory Areas in Java

Let’s have a look at how memory management in Java works. We will be going to discuss how the objects get destroyed, the working of a garbage collector, and things...

5 minutes read.

Java Command Line Arguments

Java command line arguments Command line argument is an input or argument to the program when you run the program. In Java, we can take the inputs from the console, and...

2 minutes read.

Java String lastIndexOf() method

Java String lastIndexOf() method returns last index of character or substring in a String. Syntax: Method Description int lastIndexOf(int ch)It returns last index position for the given char valueint lastIndexOf(int ch, int...

2 minutes read.

Java Constant

A constant is an unchangeable entity in coding, as its title implies. The value which cannot be altered, in other terms. We shall understand about Java constants and exactly how...

3 minutes read.