# Java Program to calculate the area of a triangle using Heron's Formula

Java 8Object Oriented ProgrammingProgramming

#### Complete Java Programming Fundamentals With Sample Projects

98 Lectures 7.5 hours

#### Get your Java dream job! Beginners interview preparation

85 Lectures 6 hours

#### Core Java bootcamp program with Hands on practice

Featured

99 Lectures 17 hours

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

Live Demo

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