Java Tutorial Java Advanced Java Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Java - Math tan() Method



The Java Math tan() method returns trigonometric tangent of an angle (angle should be in radians). In special cases it returns the following:

  • If the argument is NaN or an infinity, then the result 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 arg)

Parameters

arg Specify the angle in radian.

Return Value

Returns the trigonometric tangent of an angle.

Exception

NA.

Example:

In the example below, tan() method is used to find out the trigonometric tangent of an angle.

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.tan(Math.PI/6));   
  System.out.println(Math.tan(Math.PI/4));
  System.out.println(Math.tan(Math.PI/3));     
 }
}

The output of the above code will be:

0.5773502691896257
0.9999999999999999
1.7320508075688767

❮ Java Math Methods

5