__Java Calculating Trigonometric Functions__

__Problem__You need to compute sine, cosine, and other trigonometric functions.

__Solution__Use the trig functions in java.lang.Math . Like java.lang.Math.random( ) , all the

methods of the Math class are static, so no Math instance is necessary. This makes

sense, as none of these computations maintains any state. Note that the arguments

for trigonometric functions are in radians, not in degrees. Here is a program that

computes a few (mostly) trigonometric values and displays the values of e and PI that

are available in the math library:

// Trig.java System.out.println("Java's PI is " + Math.PI); System.out.println("Java's e is " + Math.E); System.out.println("The cosine of 1.1418 is " + Math.cos(1.1418));

The java.lang.StrictMath class, introduced in JDK 1.3, is intended to perform the
same operations as java.lang.Math but with greater cross-platform repeatability.

## No comments:

## Post a Comment