# Java Math tan() method with Examples

The java.lang.Math.tan() returns the trigonometric tangent of an angle.

• If the argument is NaN or an infinity, then the result returned is NaN.
• If the argument is zero, then the result is a zero with the same sign as the argument.
• Syntax :

```public static double tan(double angle)
Parameters :
The function has one mandatory parameter angle which is in radians.
```

Returns :
The function returns the trigonometric tangent of an angle.

Example 1 : To show the working of java.lang.Math.tan() method.

 `// Java program to demonstrate working ` `// of java.lang.Math.tan() method ` `import` `java.lang.Math; ` ` `  `class` `Gfg { ` ` `  `    ``// driver code ` `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` `        ``double` `a = ``30``; ` `         `  `        ``// converting values to radians ` `        ``double` `b = Math.toRadians(a); ` ` `  `        ``System.out.println(Math.tan(b)); ` ` `  `        ``a = ``45``; ` `         `  `        ``// converting values to radians ` `        ``b = Math.toRadians(a); ` ` `  `        ``System.out.println(Math.tan(b)); ` ` `  `        ``a = ``60``; ` `         `  `        ``// converting values to radians ` `        ``b = Math.toRadians(a); ` ` `  `        ``System.out.println(Math.tan(b)); ` ` `  `        ``a = ``0``; ` `         `  `        ``// converting values to radians ` `        ``b = Math.toRadians(a); ` ` `  `        ``System.out.println(Math.tan(b)); ` `    ``} ` `} `

Output :

```0.5773502691896257
0.9999999999999999
1.7320508075688767
0.0
```

Example 2 : To show the working of java.lang.Math.tan() method when an argument is NAN or infinity.

 `// Java program to demonstrate working ` `// of java.lang.Math.tan() method infinity case ` `import` `java.lang.Math; ` ` `  `public` `class` `GFG { ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``double` `positiveInfinity =  ` `               ``Double.POSITIVE_INFINITY; ` `        ``double` `negativeInfinity =  ` `               ``Double.NEGATIVE_INFINITY; ` `        ``double` `nan = Double.NaN; ` `        ``double` `result; ` ` `  `        ``// Here argument is negative infinity,  ` `        ``// output will be NaN ` `        ``result = Math.tan(negativeInfinity); ` `        ``System.out.println(result); ` ` `  `        ``// Here argument is positive infinity,  ` `        ``// output will also be NaN ` `        ``result = Math.tan(positiveInfinity); ` `        ``System.out.println(result); ` ` `  `        ``// Here argument is NaN, output will be NaN ` `        ``result = Math.tan(nan); ` `        ``System.out.println(result); ` `    ``} ` `} `

Output :

```NaN
NaN
NaN
```

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.