Java Reference
In-Depth Information
tions return an angle in radians,which can be converted to degrees by
means of the toDegrees() method. The following program shows the calcu-
lation of trigonometric functions and arc-functions.
// Java for Engineers
// Filename: TrigFun
// Reference: Chapter 23
// Description:
//
Calculating trigonometric functions,
//
arcfunctions, and cofunctions.
// Requires:
//
Keyin class in current directory
import java.lang.*;
strictfp class TrigFun
{
public static void main(String[] args)
{
double rads, degs, tanA, aTanA, coTanA;
// Obtain angle in degrees from user
degs = Keyin.inDouble(“Enter angle in degrees: ”);
// 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);
}
}
On the Web
The program TrigFun.java can be found in the Chapter 23 folder at
www.crcpress.com .
Search WWH ::




Custom Search