How to calculate Volume and Surface Area of Sphere in Java ?

Program to calculate Volume and Surface Area of Sphere in Java

Click here to download complete source code

package com.hubberspot.mensuration.example;

import java.util.Scanner;

public class Sphere {
 
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    double radius = 0;
   
    double volume = 0;
    double surfaceArea = 0;

    System.out.print("Enter the radius of Sphere : "); 
    radius = input.nextDouble();

    volume = (4 * Math.PI * radius * radius * radius) / 3;
   
    surfaceArea = 4 * Math.PI * radius * radius;
   
    System.out.println("");
    System.out.println("The Volume of Sphere is : " + volume);
    System.out.println("The Surface Area of Sphere is : " + surfaceArea);


  }

}


Click here to download complete source code

Output of the program :