
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
Calculate Area of Triangle Using Heron's Formula in Java
Heron’s formula gives the area of a triangle when the length of all three sides are already known.
Let’s say we have the following three sides of a triangle −
s1 = 15191235.0; s2 = 15191235.0; s3 = 1.01235479;
Now, use the Heron’s formulae to find the area −
area = (s1+s2+s3)/2.0d; resArea = Math.sqrt(area* (area - s1) * (area - s2) * (area - s3));
Example
public class Demo { public static void main(String[] args) { // sides of a triangle double s1, s2, s3; double area, resArea; // three sides of a triangle s1 = 15191235.0; s2 = 15191235.0; s3 = 1.01235479; area = (s1+s2+s3)/2.0d; resArea = Math.sqrt(area* (area - s1) * (area - s2) * (area - s3)); System.out.println("Area of Triangle = " + resArea); } }
output
Area of Triangle = 7689459.767977145
Advertisements