Java.lang Package Classes

Java Math - acos() Method



The java.lang.Math.acos() method returns arc cosine of a value. The return value will be in the range 0 through 𝜋. In special cases it returns the following:

  • If the argument is NaN or its absolute value is greater than 1, then the result is NaN.

Note: acos() is the inverse of cos().

Syntax

public static double acos(double a)

Parameters

a Specify the value whose arc cosine is to be returned.

Return Value

Returns the arc cosine of the argument.

Exception

NA.

Example:

In the example below, acos() method is used to find out the arc cosine of the given values.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.acos(0.5));   
  System.out.println(Math.acos(1));
  System.out.println(Math.acos(2));     
 }
}

The output of the above code will be:

1.0471975511965979
0.0
NaN

❮ Java.lang - Math

5