Calculate tangent in Java
Description
The following code shows how to calculate tangent.
Example
//from ww w . j a v a2s. com
public class Main {
public static void main(String[] args) {
double rads, degs, tanA, coTanA;
// Obtain angle in degrees from user
degs = 120d;
// Convert degrees to radian
rads = Math.toRadians(degs);
// Calculate tangent
tanA = Math.tan(rads);
System.out.println("Tangent = " + tanA);
}
}
The code above generates the following result.