**java.lang.StrictMath** acos(double a)

## Description

The acos(double a) method of StrictMath class returns the arc cosine of a value; the returned angle is in the range -pi/2 through pi/2.

Special cases:

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

**Notes:**

The acos(double a) method of StrictMath class is static thus it should be accessed statically which means the we would be calling this method in this format:

`StrictMath.acos(double a)`

Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java compare method non statically.

## Method Syntax

public static double acos(double a)

## Method Argument

Data Type | Parameter | Description |
---|---|---|

double | a | the value whose arc cosine is to be returned. |

## Method Returns

The acos(double a) method returns the value whose arc cosine is to be returned.

## Compatibility

Requires Java 1.3 and up

## Java StrictMath double acos(double a) Example

Below is a java code demonstrates the use of **double acos(double a) method of StrictMath class. **Basically the program below ask for two user input, one for adjacent and the other is hypotenuse. Our example program is design to calculate an angle given the user input. Take note of the usage of additional method that we have used which is toDegrees(). The method acos() returns an angle in radians which is not usually used thus we have used the toDegrees method to convert the result to degrees.

package com.javatutorialhq.java.examples; import java.util.Scanner; /* * A java example source code to demonstrate * the use of acos(double a) * method of StrictMath class */ public class StrictMathAcosExample { public static void main(String[] args) { /* assume a right triangle * Determine an angle * given the adjacent and hypotenuse */ // Ask user input for the adjacent System.out.print("Enter the adjacent:"); // declare the scanner object Scanner scan = new Scanner(System.in); // use scanner to get the user input and store it to a variable double adjacent = scan.nextDouble(); // Ask another user input System.out.print("Enter the hypotenuse:"); // store it to a variable double hypotenuse = scan.nextDouble(); // close the scanner object scan.close(); // get the result double angleRadians = StrictMath.acos(adjacent/hypotenuse); double angleDegrees = StrictMath.toDegrees(angleRadians); // print the result System.out.println("Angle of the triangle in radians: "+angleRadians); System.out.println("Angle of the triangle in degrees: "+angleDegrees); } }