Check out example codes for "java program to calculate Volume of Sphere". It will help you in understanding the concepts better.

Code Example 1

package com.tcc.java.programs;
 
import java.util.Scanner;
 
/**
 * Java Program to find volume and surface area of sphere
 */
public class VolumeOfSphere {
 
    public static void main(String[] args) {
        double radius, volume, surfaceArea;
        Scanner scanner;
        scanner = new Scanner(System.in);
        // Take input from user
        System.out.println("Enter Radius of Sphere");
        radius = scanner.nextDouble();
 
        /*
         * Surface area of Sphere = 4 X PI X Radius X Radius
         */
        surfaceArea = 4 * Math.PI * radius * radius;
        /*
         * Volume of Sphere = 4/3 X PI X Radius X Radius X 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);
    }
}

Learn ReactJs, React Native from akashmittal.com