Java Math acos() Method
The acos() method of Math class computes the trigonometric Arc Cosine (inverse of cosine ) of an angle. The value returned is between 0.0 to pi.
Syntax:
public static double acos(double a)
Parameters:
The parameter ‘a’ represents the value whose arc cosine is to be determined.
Return Value:
The acos() method returns the arc cosine of the argument .
- If we pass a positive or negative argument which is in between the range of -1 to 1, it will return the arc cosine value.
- If we pass an argument which is smaller than -1 and greater than 1, it will return NaN.
Example 1:
public class JavaMathAcosExample1 { public static void main(String[] args) { double a=1/2; //return the arc cosine value for a System.out.println("Arc cosine value : "+Math.acos(a)); } }
Output:
Arc cosine value : 1.5707963267948966
Example 2:
public class JavaMathAcosExample2 { public static void main(String[] args) { double a=Double.MIN_VALUE; System.out.println("Arc cosine value for "+a+" = "+Math.acos(a)); } }
Output:
Arc cosine value for 4.9E-324 = 1.5707963267948966
Example 3:
public class JavaMathAcosExample3 { public static void main(String[] args) { double x = 1.00005; System.out.println("Arc cosine value for "+x+" = "+Math.acos(x)); } }
Output:
Arc cosine value for 1.00005 = NaN
Example 4:
public class JavaMathAcosExample4 { public static void main(String[] args) { double x= 7.0987; double y= Math.toRadians(x); System.out.println(Math.acos(y)); } }
Output:
1.4465814600932112