How To Find Volume of the Octahedron in Java?



An octahedron is a three-dimensional (3D) shape which has eight plane faces. In other words, a polyhedron is called an octahedron which has eight faces, twelve edges, and 6 vertices. A polygonal is a three-dimensional figure with flat polygonal faces, straight edges, and sharp corners or vertices.

The word octahedron is derived from the Greek word that is Oktaedron, which means Eight faces.

Here is the diagram of the octahedron, which has side a:

Octahedron

Volume of octahedron

The volume of an octahedron is the amount of space occupied by the octahedron. To calculate the volume of an octahedron, we have a formula in math as follows:

$$\mathrm{Volume\: =\: \sqrt{2}/3\: \:a^3}$$

Where, a refers to the side of the octahedron.

In this article we will see how we can calculate the volume of the octahedron in Java.

Input & Output Scenarios

Scenario 1

Suppose the side length is 3:

Input: 3
Output: 12.72

Calculation:

Volume = \sqrt{2}/3 x 3 x 3 x 3 = 1.41 x 9 = 12.72

Scenario 2

Suppose the side length is 6:

Input: 6
Output: 101.82

Calculation:

Volume = \sqrt{2}/3 x 6 x 6 x 6 = 1.41 x 72 = 101.82

Let's see the program along with its output one by one.

Example 1

The following example calculates the volume of the octahedron, which has side 3, using the above formula:

public class Volume{
   public static void main(String args[]){
      double a = 3;
      System.out.println("The given side of octahedron: " + a);
      
      //calculate volume by using formula
      double volume = (Math.pow(a,3) * Math.sqrt(2))/3;
      System.out.println("The volume of the octahedron: " + volume);
   }
}

Output

The above program produces the following output:

The given side of octahedron: 3.0
The volume of the octahedron: 12.727922061357857

Example 2

In the example below, we define a method named calculateVolume(), which calculates the volume of an octahedron with the help of the given side value 10 using the above formula:

public class Volume {
   //method that calculate the octahedron volume
   public static double calculateVolume(double a){
      //calculating the volume of the 
      double volume = (Math.pow(a,3) * Math.sqrt(2))/3;
      return volume;
   }
   public static void main(String args[]){
      double a = 10;
      System.out.println("The give side of octahedron: " + a);
      
      //calling the method calculateVolume() to get the volume of the octahedron
      System.out.println("The volume of the octahedron is: " + calculateVolume(a));
   }
}

Output

Below is the output of the above program:

The give side of octahedron: 10.0
The volume of the octahedron is: 471.4045207910317
Updated on: 2025-06-13T12:38:19+05:30

179 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements