3.13 The Math Class

The Math class is also part of the java.lang package. As such, it is automatically available to any Java program; we do not need to use the import statement. The Math class provides two static constants (E and PI), as well as a number of static methods that save the programmer from writing some complex mathematical code.

The two constants, E and PI, are both doubles and represent, respectively, e (the base of the natural logarithm, i.e., log e = 1) and pi, the ratio of the circumference of a circle to its diameter. Approximate values of e and pi, as we know them, are 2.78 and 3.14, respectively. These constants are shown in Table 3.12.

TABLE 3.12 Static Constants of the Math Class

Constant

Value

E

e

Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.