java calculate volume of sphere code example
Example: java program to calculate Volume of Sphere
package com.tcc.java.programs;
import java.util.Scanner;
public class VolumeOfSphere {
public static void main(String[] args) {
double radius, volume, surfaceArea;
Scanner scanner;
scanner = new Scanner(System.in);
System.out.println("Enter Radius of Sphere");
radius = scanner.nextDouble();
surfaceArea = 4 * Math.PI * radius * radius;
volume = (4.0 / 3) * Math.PI * radius * radius * radius;
System.out.format("Surface Area of Sphere = %.3f\n", surfaceArea);
System.out.format("Volume of Sphere = %.3f\n", volume);
}
}