Home » Java programming language

Java Math Class static double atan(double d) with example

Java Math Class static double atan(double d) method: Here, we are going to learn about the static double atan(double d) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 01, 2019

Math Class static double atan(double d)

  • This method is available in java.lang package.
  • This method is used to return the arctangent of an angle of the given parameter in the method.
  • In this method, atan stands for arctangent of an angle.
  • This is a static method so this method is accessible with the class name too.
  • The return type of this method is double that means it returns the arctangent of the given angle is of the double datatype.
  • In this method, we pass only one parameter as an argument in the method of Math class.
  • In this method, we pass only radians type argument (i.e. First we convert given argument in radians by using toRadians() method of Math class then after we will pass the same variable in atan() method).
  • This method does not throw any exception.
  • In this method, the meaning of arctangent is the inverse or reverse tangent of the given argument.
  • The range of atan() lies –PI/2 through PI/2.

Syntax:

    public static double atan(double d){
    }

Parameter(s):

double d – A double value in radians whose arctangent to be found.

Note:

  • If we pass "NaN", it returns "NaN".
  • If we pass zero, it returns the same.

Return value:

The return type of this method is double, it returns the arctangent of the given angle.

Java program to demonstrate example of atan(double d) method

// Java program to demonstrate the example of 
// atan(double d) method of Math Class.

class AtanMethod {
    public static void main(String[] args) {
        // Here we are declaring few variables
        double d1 = -0.0;
        double d2 = Math.PI / 2;

        // Display previous value of d1 and d2
        System.out.println(" Before implementing atan() so the value of d1 is :" + d1);
        System.out.println(" Before implementing atan() so the value of d2 is :" + d2);

        // Here , we will get (-0.0) because we are passing parameter whose absolute value is -0.0
        System.out.println("After implementing atan() so the value of d1 is :" + Math.atan(d1));

        // By using toRadians() method is used to convert absolute to radians
        d2 = Math.toRadians(d2);

        // Display the value of d2 in radians form
        System.out.println("After implementing toRadians() so the value of d2 is :" + d2);

        // Here we will find arc tangent of d2 by using atan() method
        System.out.println("After implementing atan() so the value of d2 is :" + Math.atan(d2));
    }
}

Output

E:\Programs>javac AtanMethod.java

E:\Programs>java AtanMethod
Before implementing atan() so the value of d1 is :-0.0
Before implementing atan() so the value of d2 is :1.5707963267948966
After implementing atan() so the value of d1 is :-0.0
After implementing toRadians() so the value of d2 is :0.027415567780803774
After implementing atan() so the value of d2 is :0.0274087022410345



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.