Enter the radius as input. Now we calculate the surface area and volume by using formula and get the desired output.
Here is the source code of the Java Program to Find the Volume and Surface Area of Sphere.The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Volume_SurfaceArea
public static void main(String args)
double area, volume, pi = 3.14;
Scanner s = new Scanner(System.in);
System.out.print("Enter the radius of sphere:");
r = s.nextInt();
area = 3 * pi * r * r;
System.out.println("Surface Area of sphere:"+area);
volume = 1.333 * pi * r * r * r;
System.out.println("Volume of sphere:"+volume);
$ javac Volume_SurfaceArea.java $ java Volume_SurfaceArea Enter the radius of sphere:4 Surface Area of sphere:150.72 Volume of sphere:267.87968
Sanfoundry Global Education & Learning Series – 1000 Java Programs.