Published Jan 18, 2024Updated May 15, 2024
Contribute to Docs

The .cos() method returns the trigonometric cosine of the given angle. The result is in the range [-1, 1].


  • angle: This is the only parameter the .cos() method takes and is expressed in radians.

Note: If the angle is NaN or Infinity, NaN is returned.


The following example demonstrates the application of .cos() method:

public class Check {
public static void main(String args[]) {
// convert degrees to radians
double pi = Math.PI;
double degree = 60;
double radian = degree * pi/180;
//to get output up to the first decimal place
double roundedResult = Math.round(Math.cos(radian) * 10.0) / 10.0;
System.out.println("Cosine of 60 degrees is " + roundedResult);

The above example results in the following output:

Cosine of 60 degrees is 0.5

All contributors

Looking to contribute?

Learn Java on Codecademy