Java Tutorial Java Advanced Java References

Java Math - acos() Method



The Java acos() method returns arc cosine of a value. The returned 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 arg)

Parameters

arg Specify the value.

Return Value

Returns the arc cosine of the value.

Exception

NA.

Example:

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

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 Math Methods