Java.lang Package Classes

Java StrictMath - cos() Method



The java.lang.StrictMath.cos() method returns trigonometric cosine of an angle (angle should be in radians). In special cases it returns the following:

  • If the argument is NaN or an infinity, then the result is NaN.

In the graph below, cos(x) vs x is plotted.

Cos Function

Syntax

public static double cos(double a)

Parameters

a Specify the angle in radian.

Return Value

Returns the trigonometric cosine of the argument.

Exception

NA.

Example:

In the example below, cos() method is used to find out the trigonometric cosine of the given angles.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(StrictMath.cos(StrictMath.PI/6));   
  System.out.println(StrictMath.cos(StrictMath.PI/4));
  System.out.println(StrictMath.cos(StrictMath.PI/3));      
 }
}

The output of the above code will be:

0.8660254037844387
0.7071067811865476
0.5000000000000001

❮ Java.lang - StrictMath