Calculating Trigonometric Functions by Example
From Java Example Source Code
Contents |
[edit] Overview - Calculating Trigonometric Functions by Example
This Java example program shows how to use calculating trigonometric functions with Math in Java.
[edit] Java Source Code
- Package: example.math
- File: TrigFun.java
package example.math; strictfp class TrigFun { 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 cotangent coTanA = 1.0 / Math.tan(rads); System.out.println("Cotangent = " + coTanA); // Calculate arc-tangent rads = Math.atan(tanA); degs = Math.toDegrees(rads); System.out.println("Arc tangent: " + degs); // Calculate arc-cotangent rads = Math.atan(1 / coTanA); degs = Math.toDegrees(rads); System.out.println("Arc cotangent: " + degs); } }
[edit] What Result You Can Get
Run the program, you will get:
Tangent = -1.7320508075688783 Cotangent = -0.5773502691896254 Arc tangent: -60.00000000000002 Arc cotangent: -60.00000000000002
[edit] Required External Libraries and/or Files for this Java Example
Need nothing.
[edit] How to Run this Java Example Program
We recommend running this Java example program with Eclipse.
For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.
It's fairly easy.
[edit] Question & Answer
Any question?
Click edit and post your question or answer here.
