Home » Java programming language

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

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

Math Class static double acos(double d)

  • This method is available in java.lang package.
  • This method is used to return the arc cosine of the given parameter in the method. 
  • In this method, acos stands for arc cosine 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 cosine 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 acos() method). 
  • This method does not throw any exception.
  • In this method, the meaning of arc cosine is the inverse or reverse cosine of the given argument.
  • The range of acos() lies 0.0 through PI.

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 cosine of the given angle.

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

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

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

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

        // Here , we will get NaN because we are passing parameter 
        // whose absolute value is greater than 1
        System.out.println("After implementing asin() so the value of a1 is :" + Math.asin(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 sine of a2 by using asin() method
        System.out.println("After implementing asin() so the value of a2 is :" + Math.asin(a2));

        // Here , we will get 0 because we are passing parameter 
        // whose absolute value is 0
        System.out.println("After implementing asin() so the value of a3 is :" + Math.asin(a3));
    }
}

Output

E:\Programs>javac AsinMethod.java

E:\Programs>java AsinMethod
Before implementing asin() so the value of a1 is :100.0
Before implementing asin() so the value of a2 is :1.5707963267948966
Before implementing asin() so the value of a3 is :0.0
After implementing asin() so the value of a1 is :NaN
After implementing toRadians() so the value of a2 is :0.027415567780803774
After implementing asin() so the value of a2 is :0.02741900326072046
After implementing asin() so the value of a3 is :0.0





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.