Find the Area of a Triangle Given Three Sides – Heron’s Formula

Objective – Given three sides of triangle, write a program to find the area of a triangle.

Heron’s Formula for finding area of triangle:

  • First find the semi parameter of a triangle using formula, s= (a+b+c)/2 where a, b, c are three sides of triangle and s will the semi parameter.
  • Then use the below formula to get the area of triangle.
    • Area = √s(s-a)(s-b)(s-c)

Java Code:

public class AreaOfTriangle {
public static void area(double a, double b, double c){
//get the semi parameter
double s = (a + b + c)/2;
//find the area of triangle
double area = Math.sqrt(s*(sa)*(sb)*(sc));
System.out.println("Area of triangle : " + area + " sq unit");
public static void main(String[] args) {
double a = 3.5;
double b = 4.5;
double c = 6.0;

view raw
hosted with ❤ by GitHub


Area of triangle : 7.826237921249264 sq uni