Java cos() method


Java Number类Java Number class


cos() method is used to return the cosine value of the specified double type parameter.

Syntax

double cos(double d)

Parameters

  • d -- Any native data type.

Return value

Returns the cosine value of the specified double type parameter.

Example

public class Test{ 
	public static void main(String args[]){double degrees = 45.0;double radians = Math.toRadians(degrees);System.out.format("pi 的值为 %.4f%n", Math.PI);System.out.format("%.1f 度的余弦值为 %.4f%n", degrees, Math.cos(radians));}}

Compile the above program and the output result is:

pi 的值为 3.141645.0 度的余弦值为 0.7071

Java Number类Java Number class