![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Java Program to calculate area of a Tetrahedron
A Tetrahedron is a polyhedron composed of four triangular faces, six straight edges, and four vertex corners.
Following is the Java program to calculate area of a Tetrahedron −
Example
import java.io.*; public class Demo{ static double tetra_vol(int side){ double my_vol = (Math.pow(side, 3) / (6 * Math.sqrt(2))); return my_vol; } public static void main(String[] args){ int side = 4; double my_vol = tetra_vol(side); my_vol = (double)Math.round(my_vol * 100) / 100; System.out.println("The area of tetrahedron is"); System.out.println(my_vol); } }
Output
The area of tetrahedron is 7.54
A class named Demo contains a static function named 'tetra_vol' which takes 'side' as a parameter. The formula to calculate area of a tetrahedron is ‘side’ cube/(6v2). This is computed and the output is returned. In the main function, the value of size is defined, and the function is called on this value. The output is printed on the console.
Advertisements