How to calculate area of triangle by using heron’s formula in java

Heron’s formula is used to calculate the area of triangle by the given three sides of triangle.

Formula for calculating area of triangle by using Heron’s formula :-

Area of triangle =√s*(s-a)*(s-b*)(s-c)

       where s=(a+b+c)/2.0
     Note:- Here a,b,c are the three sides of triangle.
Java code for calculating area of triangle by using heron’s formula:-
import java.util.Scanner;
public class area {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
       double a,b,c,d,area_of_triangle; 
    System.err.println(“Enter the three sides of triangle”);
              a=s.nextDouble();
             b=s.nextDouble();
             c=s.nextDouble();
             d=(a+b+c)/2.0;
     area_of_triangle=Math.sqrt(d*(d-a)*(d-b)*(d-c));
      System.out.println(“area”+area_of_triangle);
           }      }java program output of herons formula

Leave a Reply