Java Math tan() Method
The tan() method of Java Math class returns the trigonometric tangent of the specified angle.
Syntax:
public static double tan(double a)
Parameters:
The parameter ‘a’ represents an angle measured in radians.
Return Value:
The tan() method returns the tangent of the argument.
- It returns zero with same sign as argument, if the argument passed is zero.
- It returns NaN, if the argument is NaN or infinity.
Example 1:
public class JavaMathTanExample1 { public static void main(String[] args) { double a=30; //return the tangent value for a System.out.println("Tangent value: "+Math.tan(a)); } }
Output:
Tangent value: -6.405331196646276
Example 2:
public class JavaMathTanExample2 { public static void main(String[] args) { //return the tangent value for Double.MIN_VALUE double a=Double.MIN_VALUE; System.out.println("Tangent value for "+a+" = "+Math.tan(a)); } }
Output:
Tangent value for 4.9E-324 = 4.9E-324
Example 3:
public class JavaMathTanExample3 { public static void main(String[] args) { //returns zero with same sign as argument, if the argument passed is zero double x = -0d; System.out.println("Tangent value for "+x+" = "+Math.atan(x)); } }
Output:
Tangent value for -0.0 = -0.0
Example 4:
public class JavaMathTanExample4 { public static void main(String[] args) { //return a tangent value for infinity double x = -6/0.0d; System.out.println("Tangent value for "+x+" = "+Math.tan(x)); } }
Output:
Tangent value for -Infinity = NaN
Example 5:
public class JavaMathTanExample5 { public static void main(String[] args) { //return a tangent value for Nan double x = Double.NaN; System.out.println("Tangent value for "+x+" = "+Math.tan(x)); } }
Output:
Tangent value for NaN = NaN