Calculate arc-tangent in Java
Description
The following code shows how to calculate arc-tangent.
Example
// www . j av a 2 s. c o m
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);
// Calculate arc-tangent
rads = Math.atan(tanA);
degs = Math.toDegrees(rads);
System.out.println("Arc tangent: " + degs);
}
}
The code above generates the following result.