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.
Input: radius = 5 Output: Surface Area ≈ 314.16 Volume ≈ 523.6 Input : radius = 3 Output: 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)
- 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)
- Display surface area and volume
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.