Probably a very simple math question, but this has me a little bit confused.
Can anybody explain to me why this:
public class volumesphere
{
public static void main(String[] args)
{
double radius = 30.5;
double PI = Math.PI;
double volume = (4.0/3) * PI * Math.pow(radius, 3);
System.out.println(volume);
}
}
Is different to this?:
public class volumesphere
{
public static void main(String[] args)
{
double radius = 30.5;
double PI = Math.PI;
double volume = (4/3) * PI * Math.pow(radius, 3);
System.out.println(volume);
}
}
Specifically in the line:
double volume = (4/3) * PI * Math.pow(radius, 3);
volume in the first case returns the correct answer at about 1.19*10^5. However, the latter returns a completely different result, around 8.9*10^4.
Can anybody explain this to me please?