Java has a built-in Math
class, defined in the java.lang
package, which contains important functions to perform basic mathematical operations.
This class has the tan()
method, which is used to compute a specified angle’s trigonometric tangent.
public static double tan(double angle);
angle
represents the double value corresponding to the angle in randians for which we have to find the trigonometric tangent.
The function returns the double value corresponding to the trigonometric tangent of the angle
.
Note:
Math.PI
is a constant equivalent to in Mathematics.
If the value of the angle
is infinity or NaN
.
Note: To convert an angle measured in radians to an equivalent angle measured in degrees and vice versa, you can use the built-in
Math.toDegrees(double angle_in_randians)
andMath.toRadians(double angle_in_degrees)
methods.
class HelloWorld {public static void main( String args[] ) {double result = Math.tan(1);System.out.println("tan(1) = " + result);result = Math.tan(0);System.out.println("tan(0) = " + result);result = Math.tan(Math.toRadians(30));System.out.println("tan(30°) = " + result);result = Math.tan(Math.toRadians(45));System.out.println("tan(45°) = " + result);result = Math.tan(Math.toRadians(60));System.out.println("tan(60°) = " + result);result = Math.tan(Math.toRadians(90));System.out.println("tan(90°) = " + result);result = Math.tan(Double.NaN);System.out.println("tan(NaN) = " + result);result = Math.tan(Double.POSITIVE_INFINITY);System.out.println("tan(∞) = " + result);}}