What is Math.acos() in Java?
Java has a built-in Math class in the java.lang package that contains important functions to perform basic mathematical operations.
The class contains the acos() method, which is used to compute the or (pronounced “inverse cos”) of a specified value.
If is x, then (x) or is .
Method definition
public static double acos(double value);
Parameters
The function has one parameter, value, that represents the double value for which we have to find the arccos.
Return value
The function returns the double value corresponding to the of value. The returned value will lie within the range to .
Note:
Math.PIis a constant equivalent to in mathematics.
If the value of value is infinity or NaN.
Note: To convert an angle measured in radians to an equivalent angle measured in degrees and vice versa, we can use the built-in
Math.toDegrees(double angle_in_randians)andMath.toRadians(double angle_in_degrees)methods.
Code
class HelloWorld {public static void main( String args[] ) {double result = Math.acos(1);System.out.println("acos(1) = " + result);result = Math.acos(0);System.out.println("acos(0) = " + result);result = Math.acos(0.48);System.out.println("acos(0.48) = " + result);result = Math.acos(0.66);System.out.println("acos(O.66) = " + result);result = Math.acos(0.8);System.out.println("acos(0.8) = " + result);result = Math.acos(1);System.out.println("acos(1) = " + result);result = Math.acos(Double.NaN);System.out.println("acos(NaN) = " + result);result = Math.acos(Double.POSITIVE_INFINITY);System.out.println("acos(∞) = " + result);}}