Facebook Page Twitter Page LinkedIn Page
× Java Tutorial Java Advanced Java Resources


The Java Math cos() method is used to return 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.

Syntax

public static double cos(double arg)

Parameters

arg Specify the angle in radian.

Return Value

Returns the trigonometric cosine of an angle.

Exception

NA.

Example:

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

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

The output of the above code will be:

0.8660254037844387
0.7071067811865476
0.5000000000000001

❮ Java Math Methods