Close

Java - Math.tan() Examples

Java Java API 


Class:

java.lang.Math

java.lang.Objectjava.lang.Objectjava.lang.Mathjava.lang.MathLogicBig

Method:

public static double tan(double a)

Returns the trigonometric tangent of an angle. Special cases:

  • 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.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Parameters:
a - an angle, in radians.
Returns:
the tangent of the argument.


Examples


package com.logicbig.example.math;

public class TanExample {

public static void main(String... args) {
findTangent(0);
findTangent(30);
findTangent(45);
findTangent(60);
findTangent(120);
}

private static void findTangent(double degrees) {
double radians = Math.toRadians(degrees);
double tanValue = Math.tan(radians);
System.out.printf("Tangent of %s degree = %.2f %n", degrees, tanValue);
}
}

Output

Tangent of 0.0 degree = 0.00 
Tangent of 30.0 degree = 0.58
Tangent of 45.0 degree = 1.00
Tangent of 60.0 degree = 1.73
Tangent of 120.0 degree = -1.73




See Also