Home » Java programming language

Java Math Class static double asin(double d) method with example

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

Math Class static double asin(double d)

  • This method is available in java.lang package.
  • This method is used to return the arc sine of the given parameter in the method.
  • In this method, asin stands for arc sine of an angle.
  • This method is static so this method is accessible with classname too.
  • The return type of this method is double that means it returns the arc sine 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 asin() method).
  • This method does not throw any exception.
  • In this method, the meaning of arc sine is the inverse or reverse sine of the given argument.
  • The range of asin() lies –PI/2 through PI/2.

Syntax:

    public static double asin(double d){
    }

Parameter(s):

double d – It's the value of an angle in radians.

Note:

  • If we pass "NaN" (Not A Number) to the function, it returns "NaN".
  • If we pass the value whose absolute value is greater than 1, it returns "NaN".

Return value:

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

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

// Java program to demonstrate the behavior of  
// acos(double d) method of Math Class.

class AcosMethod {
    public static void main(String[] args) {
        // Here we are declaring few variables
        double a1 = 100;
        double a2 = Math.PI / 2;

        // Display previous value of a1 and a2
        System.out.println(" Before implementing acos() so the value of a1 is :" + a1);
        System.out.println(" Before implementing acos() so the value of a2 is :" + a2);

        // Here , we will get NaN because we are passing parameter 
        // whose absolute value is greater than 1
        System.out.println("After implementing acos() so the value of a1 is :" + Math.acos(a1));

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

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

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

Output

E:\Programs>javac AcosMethod.java

E:\Programs>java AcosMethod
Before implementing acos() so the value of a1 is :100.0
Before implementing acos() so the value of a2 is :1.5707963267948966
After implementing acos() so the value of a1 is :NaN
After implementing toRadians() so the value of a2 is :0.027415567780803774
After implementing acos() so the value of a2 is :1.5433773235341761 


Comments and Discussions!

Load comments ↻





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