# Java Program to Find the Volume and Surface Area of Sphere

A sphere is a geometrical object in 3D space that is the surface of a ball. The sphere is defined mathematically as the set of points that are all at the same distance of radius from a given point in a 3D space.

**Example:**

Input:radius = 5Output:Surface Area ≈ 314.16 Volume ≈ 523.6Input :radius = 3Output:Surface Area ≈ 113.1 Volume ≈ 113.1

Surface area of a sphere = 4*3.14*(r*r)

Volume of a sphere = (4/3)*3.14*(r*r*r)

__Algorithm__

- Initializing value of r as 5.0, surface area as 0.0,volume as 0.0
- Calculating surface area and volume of a sphere using the below formulas
- Surface area=4*3.14(r*r)
- Volume=(4/3)3.14(r*r*r)
- Display surface area and volume

__Implementation:__

## Java

`// Java Program to Find the Volume and Surface Area of` `// Sphere` `class` `surfaceareaandvolume {` ` ` `public` `static` `void` `main(String[] args)` ` ` `{` ` ` `double` `r = ` `5.0` `, surfacearea = ` `0.0` `, volume = ` `0.0` `;` ` ` `surfacearea = ` `4` `* ` `3.14` `* (r * r);` ` ` `volume = ((` `double` `)` `4` `/ ` `3` `) * ` `3.14` `* (r * r * r);` ` ` ` ` `System.out.println(` `"surfacearea of sphere ="` ` ` `+ surfacearea);` ` ` ` ` `System.out.println(` `"volume of sphere ="` `+ volume);` ` ` `}` `}` |

**Output**

surfacearea of sphere =314.0 volume of sphere =523.3333333333334

**Time Complexity: **O(1)

**Space Complexity:** O(1)

Attention reader! Don’t stop learning now. Get hold of all the important **Java Foundation** and Collections concepts with the **Fundamentals of Java and Java Collections Course** at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer **Complete Interview Preparation Course****.**