java program to calculate volume of sphere

Solutions on MaxInterview for java program to calculate volume of sphere by the best coders in the world

showing results for - "java program to calculate volume of sphere"
Sherlock
27 Aug 2016
1package com.tcc.java.programs;
2 
3import java.util.Scanner;
4 
5/**
6 * Java Program to find volume and surface area of sphere
7 */
8public class VolumeOfSphere {
9 
10    public static void main(String[] args) {
11        double radius, volume, surfaceArea;
12        Scanner scanner;
13        scanner = new Scanner(System.in);
14        // Take input from user
15        System.out.println("Enter Radius of Sphere");
16        radius = scanner.nextDouble();
17 
18        /*
19         * Surface area of Sphere = 4 X PI X Radius X Radius
20         */
21        surfaceArea = 4 * Math.PI * radius * radius;
22        /*
23         * Volume of Sphere = 4/3 X PI X Radius X Radius X Radius
24         */
25        volume = (4.0 / 3) * Math.PI * radius * radius * radius;
26 
27        System.out.format("Surface Area of Sphere = %.3f\n", surfaceArea);
28        System.out.format("Volume of Sphere = %.3f\n", volume);
29    }
30}
31