Java .tan()

shlokPrajapati6005371709's avatar
Published Oct 21, 2022Updated Jun 10, 2025
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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours

Syntax

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.

Example

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
System.out.println(Math.tan(x));
x = 0.0;
System.out.println(Math.tan(x));
}
}

This will produce the following output:

1.6197751905438615
0.0

All contributors

Contribute to Docs

Learn Java on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours