// (from the Carter book)
// Example 7 (parts a,b,c,d and e). How to use the
// trigonometric Math functions of Math.sin, Math.cos,
// Math.tan and Math.cot. These methods will
// be explained individually, as they are demonstrated.
import java.lang.*;
public class MathMethodExamples4
{
public static void main (String[] args)
{
// Part (7a) -- Math.sin -- returns the sine of a given
// angle, 60 degrees, using the value of Math.PI radians = 180 degrees.
// Sine returns the angle, 60 degrees, in radians:
// System.out.println (Math.sin (Math.PI/3));
// Part (7b) -- Math.cos -- returns the cosine of a given
// angle, 5 degrees, using the value of Math.PI radians = 180 degrees,
// divided by 180, then multiplied by 5. Cosine returns the angle,
// 5 degrees, in radians:
// System.out.println (Math.cos (Math.PI/180 * 5));
// Part (7c) -- Math.tan -- returns the tangent of a given
// angle, 45 degrees, using the value of Math.PI radians = 180 degrees,
// divided by 4. Tangent returns the angle, 45 degrees, in radians:
// System.out.println (Math.tan (Math.PI / 4)); // s/b rounded to 1.0
// Part (7d) -- Math.cos -- see description in Part (7b). This time,
// cosine returns the angle, 180 degrees, in radians, using the value
// of Math.PI radians = 180 degrees:
// System.out.println (Math.cos (Math.PI));
// Part (7e) -- Math.cot -- returns the co-tangent of a given
// angle, 0 degrees, but results in an infinite value:
// System.out.println (1 / Math.tan(0));
// Other trigonometric functions in the Math class are: Math.asin,
// Math.acos and Math.atan -- these are the inverse trig functions.
// As arguments / parameters, they take, respectively, Math.sin,
// Math.cos and Math.tan in parentheses following the function name.
} // main method
} // MathMethodExamples4 class
No comments:
Post a Comment