Java Reference
In-Depth Information
want to use separated by a period. For example, the sqrt() method calculates the square root of whatever
you place between the parentheses. To use the sqrt() method to produce the square root of the floating-
point value that you've stored in a variable, aNumber , you write Math.sqrt(aNumber) .
The class Math includes a range of methods for standard trigonometric functions. The most commonly
used are shown in Table 2-3 :
TABLE 2-3 : Class Math Trigonometric Functions
As with all methods, the arguments that you put between the parentheses following the method name can
be any expression that produces a value of the required type. The toRadians() method in the Math class
converts a double argument that is an angular measurement in degrees to radians. There is a complement-
ary method, toDegrees() , to convert in the opposite direction. The Math class also defines double values
for e and π, which you can access as Math.E and Math.PI respectively. If you are not familiar with these
trigonometric operations you can safely ignore them.
You also have a range of numerical functions implemented as static methods in the Math class and at least
some of these are useful to you. These are shown in Table 2-4 :
TABLE 2-4 : Math Class Numerical Functions
 
 
 
 
Search WWH ::




Custom Search