Java atan() Method Last Updated : 27 May, 2025 Comments Improve Suggest changes Like Article Like Report The Math.atan() method in Java is used to calculate the arc tangent of a given value. This method is part of the java.lang.Math package. In this article, we are going to discuss the working of this method with regular values and for special cases such as infinity and NaN. This method is very useful when we have to work with angles.Special Cases:If the argument is NaN, then the result will be NaN. If the argument is +0.0, the result will be +0.0If the argument is -0.0, the result will be -0.0If the argument is positive infinity, the result will be π/2.If the argument is negative infinity, the result will be -π/2.Syntax of atan() MethodThe syntax of the atan() method is:public static double atan(double a)Parameter: This method takes a single parameter "a", of type double, for which we are calculating the arc tangent.Return Type: This method returns the arc tangent of the argument.Examples of Java atan() MethodNow, we are going to discuss some examples for better understanding.Example 1: In this example, we will see the basic usage of the Math.atan() method. Java // Java Program to demonstrate the working of // Math.atan() method with regular values import java.lang.Math; public class Geeks { public static void main(String[] args) { double a = Math.PI; System.out.println("atan(pi) = " + Math.atan(a)); double c = 344.0; System.out.println("atan(344.0) = " + Math.atan(c)); double d = 0.0; System.out.println("atan(+0.0) = " + Math.atan(d)); double e = -0.0; System.out.println("atan(-0.0) = " + Math.atan(e)); double f = 1.5; System.out.println("atan(1.5) = " + Math.atan(f)); System.out.println("atan(NaN) = " + Math.atan(Double.NaN)); System.out.println("atan(+Infinity) = " + Math.atan(Double.POSITIVE_INFINITY)); System.out.println("atan(-Infinity) = " + Math.atan(Double.NEGATIVE_INFINITY)); } } Output: Explanation: In the above example, we are calculating the atan for different types of values.Example 2: In this example, we will use atan() method to handle infinity and NaN. Java // Java program to demonstrate // handling NaN and Infinity import java.lang.Math; public class Geeks { public static void main(String[] args) { // Positive Infinity double p = Double.POSITIVE_INFINITY; System.out.println("atan(+Infinity) = " + Math.atan(p)); // Negative Infinity double n = Double.NEGATIVE_INFINITY; System.out.println("atan(-Infinity) = " + Math.atan(n)); // NaN (Not a Number) double n1 = Double.NaN; System.out.println("atan(NaN) = " + Math.atan(n1)); // NaN generated from 0.0 / 0.0 double n2 = 0.0 / 0.0; System.out.println("atan(0.0 / 0.0) = " + Math.atan(n2)); } } Outputatan(+Infinity) = 1.5707963267948966 atan(-Infinity) = -1.5707963267948966 atan(NaN) = NaN atan(0.0 / 0.0) = NaN Explanation: In the above example, we are handling the cases where the input value is positive infinity and negative infinity and NaN. Comment More infoAdvertise with us Next Article Java atan() Method N Niraj_Pandey Follow Improve Article Tags : Java Programs java-math Java-Library Similar Reads Java Programs - Java Programming Examples In this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.Java is one of the most popular programming languages today because of its 8 min read Reverse a String in Java In Java, reversing a string means reordering the string characters from the last to the first position. Reversing a string is a common task in many Java applications and can be achieved using different approaches. In this article, we will discuss multiple approaches to reverse a string in Java with 7 min read Java Pattern Programs - Learn How to Print Pattern in Java In many Java interviews Star, number, and character patterns are the most asked Java Pattern Programs to check your logical and coding skills. Pattern programs in Java help you to sharpen your looping concepts (especially for loop) and problem-solving skills in Java. If you are looking for a place t 15+ min read Java Exercises - Basic to Advanced Java Practice Programs with Solutions Looking for Java exercises to test your Java skills, then explore our topic-wise Java practice exercises? Here you will get 25 plus practice problems that help to upscale your Java skills. As we know Java is one of the most popular languages because of its robust and secure nature. But, programmers 7 min read Prime Number Program in Java A prime number is a natural number greater than 1, divisible only by 1 and itself. Examples include 2, 3, 5, 7, and 11. These numbers have no other factors besides themselves and one.In this article, we will learn how to write a prime number program in Java when the input given is a Positive number. 6 min read Java Multithreading Tutorial Threads are the backbone of multithreading. We are living in the real world which in itself is caught on the web surrounded by lots of applications. With the advancement in technologies, we cannot achieve the speed required to run them simultaneously unless we introduce the concept of multi-tasking 15+ min read Program to Print Fibonacci Series in Java The Fibonacci series is a series of elements where the previous two elements are added to generate the next term. It starts with 0 and 1, for example, 0, 1, 1, 2, 3, and so on. We can mathematically represent it in the form of a function to generate the n'th Fibonacci number because it follows a con 5 min read static Keyword in Java The static keyword in Java is mainly used for memory management, allowing variables and methods to belong to the class itself rather than individual instances. The static keyword is used to share the same variable or method of a given class. The users can apply static keywords with variables, method 9 min read Java Program to Check Whether a String is a Palindrome A string in Java can be called a palindrome if we read it from forward or backward, it appears the same or in other words, we can say if we reverse a string and it is identical to the original string for example we have a string s = "jahaj " and when we reverse it s = "jahaj"(reversed) so they look 8 min read Initializing a List in Java The Java.util.List is a child interface of Collection. It is an ordered collection of objects where duplicate values can be stored. Since List preserves the insertion order, it allows positional access and insertion of elements. List Interface is implemented by the ArrayList, LinkedList, Vector, and 6 min read Like