Java Data Type Tutorial - Java Math.cos(double a)








Syntax

Math.cos(double a) has the following syntax.

public static double cos(double a)

Example

In the following code shows how to use Math.cos(double a) method.

//  www .j  av  a  2s.  c  o  m

public class Main {

   public static void main(String[] args) {

      double x = 45.0;
      double y = 180.0;

      // convert them to radians
      x = Math.toRadians(x);
      y = Math.toRadians(y);

      // calculate their cosine
      System.out.println("Math.cos(" + x + ")=" + Math.cos(x));
      System.out.println("Math.cos(" + y + ")=" + Math.cos(y));

   }
}

The code above generates the following result.