Published Oct 21, 2022
Contribute to Docs

The Math.tan() method returns the tangent of an angle given in radians. The function accepts all real numbers except the values where cos(x) is equal to zero.


Math.tan(double x)

Here, x is the argument passed to the function. Math.tan() accepts all real numbers as arguments.

  • If the argument is NaN or an infinity, then the result returned is NaN.
  • If the argument is zero, then the result is also zero with same sign.


This example uses .tan() to return the tangent for (x):

// Main.java
public class Main {
public static void main(String[] args) {
double x = Math.PI / 2.0; // Radians
x = 0.0;

This will produce the following output:


All contributors

Looking to contribute?

Learn Java on Codecademy