How To Find Volume of Hemisphere in Java?



A Hemisphere refers to the exact half of a sphere, which means if we divide a sphere into two equal parts, then we will get two hemispheres. The hemisphere is a three-dimensional geometrical shape that has one flat face.

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:

Hemisphere

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
Updated on: 2025-06-05T21:36:00+05:30

619 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements