Java.lang Package Classes

Java Math - tan() Method



The java.lang.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.

In the graph below, tan(x) vs x is plotted.

Tan Function

Syntax

public static double tan(double a)

Parameters

a Specify the angle in radian.

Return Value

Returns the trigonometric tangent of the argument.

Exception

NA.

Example:

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

import java.lang.*;

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.lang - Math