Skip to content

Instantly share code, notes, and snippets.

@spukles
Created September 21, 2022 17:41
Show Gist options
  • Save spukles/475b122dc661a82defb14e32ddbd480e to your computer and use it in GitHub Desktop.
Save spukles/475b122dc661a82defb14e32ddbd480e to your computer and use it in GitHub Desktop.
import java.util.Scanner;
import java.text.*;
public class Sphere {
public static void main(String[] args){
// Declare variables
Scanner sc = new Scanner(System.in);
final double PI = Math.PI;
double radius = 0.0;
double circumference, volume, surfaceArea;
// Get input
System.out.print("Input Radius:");
radius = sc.nextDouble();
// Calculate circumference/volume/area
circumference = Math.PI * 2 * radius;
volume = (4.0/3) * Math.PI * radius * radius * radius;
surfaceArea = Math.PI * 4 * radius * radius ;
// Format values
DecimalFormat df = new DecimalFormat("0.####");
// Output values
System.out.println("Circumference:" + df.format(circumference));
System.out.println("Volume: " + df.format(volume));
System.out.println("Surface Area: " + df.format(surfaceArea));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment