8.4. The Math Class

Math provides a range of arithmetic methods not available as built-in operators. All of these methods are static, so there would never be any reason to create an instance of the Math class.


public static final double E

This constant is e, the base for natural logarithms, 2.7182818284590452354.

public static final double PI

This constant is π, 3.14159265358979323846.

General-Purpose Methods

public static int abs(int num)

public static long abs(long num)

public static float abs(float num)

public static double abs(double num)

These methods return the absolute value of the specified number.

public static double ceil(double num)

public static double floor(double num)

The ceil method returns a double corresponding to the smallest ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.