Created
September 21, 2022 17:41
-
-
Save spukles/475b122dc661a82defb14e32ddbd480e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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