- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 Dodecahedron in Java?
A dodecahedron is a three-dimensional shape which has twelve flat faces. It is derived from two Greek words i.e. ‘dodeka’ which means 12 and ‘hedra’ which means face. Simply, it is a polyhedron with twelve sides or faces. It is also called dodecahedron.
Formula to find volume of dodecahedron −
$$\mathrm{Volume \:=\: (15\: +\: 7\sqrt{5})*a^3/4}$$
Where, ‘a’ refers to the edge of the dodecahedron.
In this article we will see how we can find the volume of the dodecahedron in Java.
To show you some instances
Instance-1
Suppose the edge length is 4
Then according to the volume formula of dodecahedron −
Volume = 490.44
Instance-2
Suppose the edge length is 3
Then according to the volume formula of dodecahedron −
Volume = 206.904
Instance-3
Suppose the edge length is 4.2
Then according to the volume formula of dodecahedron −
Volume = 567.745
Syntax
To get the square root of a number we have inbuilt sqrt() method in the Math class of java.lang package.
Following is the syntax to get square root of any number by using the method.
double squareRoot = Math.sqrt(input_vale)
Similarly, to get the power of any number raised to the power of another number in Java we have inbuilt java.lang.Math.pow() method.
Following is the syntax to get power of 3 by using the method
double power = Math.pow (inputValue,3)
Algorithm
Step 1 − Get the edge length of the dodecahedron either by initialization or by user input.
Step 2 − Find the volume of the dodecahedron by using the volume formula
Step 3 − Print the result.
Multiple Approaches
We have provided the solution in different approaches.
By Using User Input Value
By Using User Defined Method
Let’s see the program along with its output one by one.
Approach-1: By Using Static Input Value
In this approach the edge length of the dodecahedron will be declared in the program. Then by using the algorithm find the volume.
Example
import java.util.*; public class Main{ //main method public static void main(String args[]){ //declared the edge length double a=5.5; System.out.println("Enter the length of edge:"+a); //Find volume by using formula double volume= (((15 + (7 * (Math.sqrt(5)))) / 4) * (Math.pow(a, 3))); //Print the result System.out.println("Volume of Dodecahedron: " +volume); } }
Output
Enter the length of edge:5.5 Volume of Dodecahedron: 1274.9514170739233
Approach-2: By Using User Defined Method
In this approach the user will be asked to take the input of the edge length of the dodecahedron. Then call a user defined method by passing this length as parameter and inside the method find the volume by using the volume formula of dodecahedron.
Example
import java.util.*; public class Main{ //main method public static void main(String args[]){ //declared the edge length double a=6; System.out.println("The length of edge: "+a); //calling the method findVolume(a); } //user defined method to find volume of dodecahedron public static void findVolume(double a){ //Find volume by using formula double volume= (((15 + (7 * (Math.sqrt(5)))) / 4) * (Math.pow(a, 3))); //Print the result System.out.println("Volume of Dodecahedron: " +volume); } }
Output
The length of edge: 6.0 Volume of Dodecahedron: 1655.2336954949205
In this article, we explored how to find volume of the dodecahedron in Java by using different approaches.