1
2strictfp class TrigFun {
3 public static void main(String[] args) {
4 double rads, degs, tanA, coTanA;
5
6 // Obtain angle in degrees from user
7 degs = 120d;
8 // Convert degrees to radian
9 rads = Math.toRadians(degs);
10
11 // Calculate tangent
12 tanA = Math.tan(rads);
13 System.out.println("Tangent = " + tanA);
14
15 // Calculate cotangent
16 coTanA = 1.0 / Math.tan(rads);
17 System.out.println("Cotangent = " + coTanA);
18
19 // Calculate arc-tangent
20 rads = Math.atan(tanA);
21 degs = Math.toDegrees(rads);
22 System.out.println("Arc tangent: " + degs);
23
24 // Calculate arc-cotangent
25 rads = Math.atan(1 / coTanA);
26 degs = Math.toDegrees(rads);
27 System.out.println("Arc cotangent: " + degs);
28 }
29}
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44