Java Math tan() method with Examples
Last Updated :
06 Apr, 2018
The java.lang.Math.tan() returns the trigonometric tangent of an angle.
- 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 :
public 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.
Example 1 : To show the working of java.lang.Math.tan() method.
import java.lang.Math;
class Gfg {
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));
}
}
|
Output :
0.5773502691896257
0.9999999999999999
1.7320508075688767
0.0
Example 2 : To show the working of java.lang.Math.tan() method when an argument is NAN or infinity.
import java.lang.Math;
public class GFG {
public static void main(String[] args)
{
double positiveInfinity =
Double.POSITIVE_INFINITY;
double negativeInfinity =
Double.NEGATIVE_INFINITY;
double nan = Double.NaN;
double result;
result = Math.tan(negativeInfinity);
System.out.println(result);
result = Math.tan(positiveInfinity);
System.out.println(result);
result = Math.tan(nan);
System.out.println(result);
}
}
|
Output :
NaN
NaN
NaN
Share your thoughts in the comments
Please Login to comment...