Java Math tan() Method Last Updated : 07 May, 2025 Comments Improve Suggest changes Like Article Like Report The Math.tan() method of java.lang.Math class calculates the trigonometric tangent of an angle. Suppose there is a right-angled triangle, so tan(angle) is the opposite side divided by the adjacent side. 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 of Math tan() Methodpublic 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.Note: Convert degrees with Math.toRadians(degrees) before passing to tan().Examples of Java Math tan() MethodExample 1: In this example, we will see the working of Math.tan() method with basic angles. Java // Java program to demonstrate working // of java.lang.Math.tan() method import java.lang.Math; class Geeks { public static void main(String args[]) { double a = 30; double b = Math.toRadians(a); System.out.println(Math.tan(b)); a = 45; b = Math.toRadians(a); System.out.println(Math.tan(b)); a = 60; b = Math.toRadians(a); System.out.println(Math.tan(b)); a = 0; b = Math.toRadians(a); System.out.println(Math.tan(b)); } } Output0.5773502691896257 0.9999999999999999 1.7320508075688767 0.0 Explanation: Here, we convert each angle that are 30 degree, 45 degree, 60 degree, 0 degree, to radians and print the tangent value.Example 2: In this example, we will see, what happens with NaN and infinity cases. Java // Java program to demonstrate working of // java.lang.Math.tan() method when argument is NaN or Infinity import java.lang.Math; class Geeks { public static void main(String args[]) { double positiveInfinity = Double.POSITIVE_INFINITY; double negativeInfinity = Double.NEGATIVE_INFINITY; double nan = Double.NaN; double result; // argument is negative infinity result = Math.tan(negativeInfinity); System.out.println(result); // argument is positive infinity result = Math.tan(positiveInfinity); System.out.println(result); // argument is NaN result = Math.tan(nan); System.out.println(result); } } OutputNaN NaN NaN Explanation: As we discussed earlier, here, NaN or infinite input produces NaN. Comment More infoAdvertise with us C ChetnaAgarwal Follow Improve Article Tags : Misc Java Technical Scripter Java-Library Java-lang package java-math +2 More Practice Tags : JavaMisc Similar Reads JavaScript Math tan() Method The Javas Math.tan() method in Javascript is used to return the tangent of a number. The Math. tan() method returns a numeric value that represents the tangent of the angle. The tan() is a static method of Math, therefore, it is always used as Math.tan(), rather than as a method of a Math object cre 2 min read C# | Math.Tan() Method Math.Tan() is an inbuilt Math class method which returns the tangent of a given double value argument(specified angle). Syntax: public static double Tan(double num) Parameter: num: It is the angle(measured in radian) whose tangent is to be returned and the type of this parameter is System.Double. Re 2 min read JavaScript Math tanh() Method Javascript Math.tanh() method is used to calculate the value of the hyperbolic tangent of a number. Syntax:Math.tanh(x)Parameter: This method accepts a single parameter as mentioned above and described below:x: which is a number for which the value of hyperbolic tangent is going to be calculated.Ret 3 min read C# | Math.Tanh() Method Math.Tanh() is the inbuilt Math class method which returns the hyperbolic tan of a given double value argument. The result will be NaN if the given argument is NaN.Syntax: public static double Tanh(double num) Parameter: num: It is the number whose hyperbolic tan is to be returned and type of this p 2 min read C# | Math.Sin() Method Math.Sin() is an inbuilt Math class method which returns the sine of a given double value argument(specified angle). Syntax: public static double Sin(double num) Parameter: num: It is the angle(measured in radian) whose sine is to be returned and the type of this parameter is System.Double. Return V 2 min read Java Math tan() method with Examples The Math.tan() method of java.lang.Math class calculates the trigonometric tangent of an angle. Suppose there is a right-angled triangle, so tan(angle) is the opposite side divided by the adjacent side. If the argument is NaN or an infinity, then the result returned is NaN.If the argument is zero, t 2 min read Like