StrictMath acos() Method in Java

The java.lang.StrictMath.acos() is an inbuilt method which returns cosine of a given argument and an angle. The angle which is returned within the range between 0.0 and pi. Note: If the absolute value of the argument is greater than 1 or the argument is itself a NaN then the result is also NaN. Syntax:
public static double acos(double num)
Parameters: The method accepts one parameter num which is of double type and refers the arc whose cosine is to be returned. Return Value: The method returns the arc cosine of the argument. Examples :
Input: num = 0.45 Output: 1.1040309877476002 Input: num = 8.9 Output: NAN
Below programs illustrate the java.lang.StrictMath.acos() method: Program 1: For positive numberĀ
java
// Java program to illustrate the// java.lang.StrictMath.acos()import java.lang.*;Ā
public class Geeks {Ā
Ā Ā Ā Ā public static void main(String[] args)Ā Ā Ā Ā {Ā
Ā Ā Ā Ā Ā Ā Ā Ā double num1 = 0.65, num2 = 6.30;Ā
Ā Ā Ā Ā Ā Ā Ā Ā // It returns the arc cosine of a valueĀ Ā Ā Ā Ā Ā Ā Ā double acosValue = StrictMath.acos(num1);Ā Ā Ā Ā Ā Ā Ā Ā System.out.println("The arc cosine value of "+Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā num1 + " = " + acosValue);Ā
Ā Ā Ā Ā Ā Ā Ā Ā acosValue = StrictMath.acos(num2);Ā Ā Ā Ā Ā Ā Ā Ā System.out.println("arc cosine value of "+Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā num2 + " = " + acosValue);Ā Ā Ā Ā }} |
Output:
The arc cosine value of 0.65 = 0.863211890069541 arc cosine value of 6.3 = NaN
Program 2: For negative number.Ā
java
// Java program to illustrate the// java.lang.StrictMath.acos()import java.lang.*;Ā
public class Geeks {Ā
Ā Ā Ā Ā public static void main(String[] args)Ā Ā Ā Ā {Ā
Ā Ā Ā Ā Ā Ā Ā Ā double num1 = -0.65, num2 = -6.30;Ā
Ā Ā Ā Ā Ā Ā Ā Ā // It returns the arc cosine of a valueĀ Ā Ā Ā Ā Ā Ā Ā double acosValue = StrictMath.acos(num1);Ā Ā Ā Ā Ā Ā Ā Ā System.out.println("The arc cosine value of "+Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā num1 + " = " + acosValue);Ā
Ā Ā Ā Ā Ā Ā Ā Ā acosValue = StrictMath.acos(num2);Ā Ā Ā Ā Ā Ā Ā Ā System.out.println("arc cosine value of "+Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā num2 + " = " + acosValue);Ā Ā Ā Ā }} |
Output:
The arc cosine value of -0.65 = 2.278380763520252 arc cosine value of -6.3 = NaN



