Skip to content

Instantly share code, notes, and snippets.

@haashimrehan
Created September 11, 2018 18:34
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/a480cbc3e803370a2cf4e593a8011188 to your computer and use it in GitHub Desktop.
Save haashimrehan/a480cbc3e803370a2cf4e593a8011188 to your computer and use it in GitHub Desktop.
public class VolumeCalc {
public static void main(String []args){
// Declare Variables
double radius = 10;
double volume = 0;
//While the radius is less than 200
//update radius value
while(radius <= 2000){
//Calculate volume
volume = 4.0/3.0 * Math.PI * Math.pow(radius, 3);
//Output to screen
System.out.println("The volume of a sphere with a radius of " + radius + " is " + volume);
//add 10 to the radius
radius += 0.00001;
if (volume > 10000) {
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment