A better volume
In Java the term
(4 / 3)
evaluates to the integer 1
so the volume evaluates to 3.14159 (or PI)
instead of the proper value 4.18878..
resulting in a huge error, and
providing no error message!
A better version is:
// Volume of a sphere: corrected
double radius, volume;
radius = 1.0; // a unit sphere
volume = (4.0 / 3.0) * 3.14159 * radius * radius * radius;
System.out.println (volume);
The main line can also be written as
volume = (4.0 / 3.0) * Math.PI * radius * radius * radius;
or even
volume = (4.0 / 3.0) * Math.PI * Math.pow (radius, 3.0);
Beware; Be Aware.