Skip to content

Instantly share code, notes, and snippets.

@haashimrehan
Created September 7, 2018 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haashimrehan/7b32cf52730cf48138e428a1c9d8b4bd to your computer and use it in GitHub Desktop.
Save haashimrehan/7b32cf52730cf48138e428a1c9d8b4bd to your computer and use it in GitHub Desktop.
Calculate the volume of three spheres
public class ThreeSphereCalc{
public static void main(String []args){
final double PI = 3.14159265358979;
double radius = 10;
double volume = 4.0/3.0*PI*radius*radius*radius;
System.out.println("The sphere with a radius of "+radius+" has a volume of " + volume);
radius = 20;
volume = 4.0/3.0*PI*radius*radius*radius;
System.out.println("The sphere with a radius of "+radius+" has a volume of " + volume);
radius = 30;
volume = 4.0/3.0*PI*radius*radius*radius;
System.out.println("The sphere with a radius of "+radius+" has a volume of " + volume);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment