This is a Java Program to Find the Area of a Triangle Given Three Sides.

Semiperimeter = (a+b+c)/2

Area = sqrt(sp*(sp-a)*(sp-b)*(sp-c))

Semiperimeter = (a+b+c)/2

Area = sqrt(sp*(sp-a)*(sp-b)*(sp-c))

Enter the length of three sides of triangle. Now we use the Heron’s formula to get the area of triangle.

Here is the source code of the Java Program to Find the Area of a Triangle Given Three Sides. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

public class Triangle

`{`

public static void main(String args[])

`{`

double s1, s2, s3, s4, area;

Scanner s = new Scanner(System.in);

System.out.print("Enter the first side :");

s1 = s.nextDouble();

System.out.print("Enter the second side :");

s2 = s.nextDouble();

System.out.print("Enter the third side :");

s3 = s.nextDouble();

s4 = (s1 + s2 + s3 )/ 2 ;

area = Math.sqrt(s4 * (s4 - s1) * (s4 - s2) * (s4 - s3));

System.out.print("Area of Triangle is:"+area+" sq units");

`}`

`}`

Output:

$ javac Triangle.java $ java Triangle Enter the first side :3 Enter the second side :4 Enter the third side :5 Area of Triangle is:6.0 sq units

**Sanfoundry Global Education & Learning Series – 1000 Java Programs.**

Here’s the list of Best Reference Books in Java Programming, Data Structures and Algorithms.