...
In this compliant solution, a constant PI
is declared and initialized to 3.14
. Thereafter, it is referenced in the code whenever the value of ?
of π
is needed.
Code Block | ||
---|---|---|
| ||
private static final double PI = 3.14; double area(double radius) { return 4.0 * PI * radius * radius; } double volume(double radius) { return 4.0/3.0 * PI * radius * radius * radius; } double greatCircleCircumference(double radius) { return 2 * PI * radius; } |
This technique reduces clutter and promotes maintainability. If a more precise approximation of the value of ?
of π
is required, the programmer can simply redefine the constant.
...