
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How To Find Volume of Hemisphere in Java?
Following is the diagram of the Hemisphere, which gives an idea about the space it occupies and its radius that helps you to calculate the volume:
Volume of the Hemisphere
The volume of the hemisphere is the amount of space occupied by the hemisphere. It is half of the volume of the sphere with the same radius (r). Here is the formula to calculate the volume of a hemisphere:
Volume of Hemisphere = (2 * pi * r * r) / 3
Here, 'r' refers to the radius of the hemisphere.
Input & Output Scenarios
Below are a few input and output scenarios that will help you understand how to find the volume of the Hemisphere by using the above formula:
Scenario 1
Suppose the radius(r) of hemisphere is 4.5:
Input: 4.5 Output: Yes
Calculation:
Volume = (2 x 3.14 x 4.5 x 4.5 x 4.5) / 3 = 190.755
Scenario 2
Suppose, the given radius(r) of hemisphere is 3:
Input: 3 Output: No
Calculation:
Volume = (2 x 3.14 x 3 x 3 x 3) / 3 = 56.548
Here, the 3.14 represents the value of PI. In Java, you can use Math.PI to obtain the value of PI.
Example 1
The following example calculates the volume of the Hemisphere using the given hemisphere radius 6:
public class Hemisphere { public static void main(String[] args) { double radius = 6; System.out.println("The radius of hemisphere: " + radius); //calculating hemisphere volume by using formula double volume = (2 * Math.PI * radius * radius * radius) / 3; //print the result System.out.println("The volume of the Hemisphere: " + volume); } }
The above program produces the following output:
The radius of hemisphere: 6.0 The volume of the Hemisphere: 452.3893421169302
Example 2
In this example, we define a method calculateVolume(), which will calculate the volume of a hemisphere having a radius of 5.5 using the above hemisphere volume formula:
public class Hemisphere { //method to calculate the volume of the Hemisphere public static void calculateVolume(double radius) { //calculate volume using the formula double volume = (2 * Math.PI * Math.pow(radius,2) * radius) / 3; //print the result System.out.println("Volume of Hemisphere is : " + volume); } public static void main(String[] args) { double radius = 5.5; System.out.println("The radius of hemisphere: " + radius); //calling the calculateVolume() method to calculate the hemisphere calculateVolume(radius); } }
Below is the output of the above program:
The radius of hemisphere: 5.5 Volume of Hemisphere is : 348.45498516066795