Home >>Java Math Methods >Java Math.cos() method

Java Math.cos() method

Java Math.cos() method

The java.lang. Math.cos() Method in Java Math is used to return an angle of the trigonometric cosine. This method returns the value from -1 to 1.

Syntax

public static double cos(double a)

Parameters

a = This method is used as an angle, in radians

Returns

It is Used to returns the cosine value of the argument.

  1. If the statement is positive or negative integer, then this method returns the value of Cosine.
  2. If -1 or infinity is the argument, the process will return -1.

Java Math.cos() Method Example 1


public class MyClass
{  
    public static void main(String[] args)   
    {  
        double x = 35;  
        double y = Math.toRadians(x);  
        System.out.println(Math.cos(y));  
    }  
}  

Output:
0.8191520442889918

Java Math.cos() Method Example 2


    public class MyClass  
    {  
        public static void main(String[] args)   
        {  
            double x = 1.0;  
            double y = Math.toRadians(x);  
            System.out.println(Math.cos(y));  
        }  
    }  

Output:
0.9998476951563913

No Sidebar ads