.cos()
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].
Syntax
Math.cos(angle)
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.
Example
The following example demonstrates the application of .cos()
method:
public class Check {public static void main(String args[]) {// convert degrees to radiansdouble pi = Math.PI;double degree = 60;double radian = degree * pi/180;//to get output up to the first decimal placedouble 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
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.