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








Syntax

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

public static double tan(double a)

Example

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

public class Main {
//from   www . ja  va2s  . c  om
   public static void main(String[] args) {

      double x = 45;
      double y = -180;

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

      // print the tangent of these doubles
      System.out.println("Math.tan(" + x + ")=" + Math.tan(x));
      System.out.println("Math.tan(" + y + ")=" + Math.tan(y));

   }
}

The code above generates the following result.