Java program to find area of scalene triangle

Java program to find area of scalene triangle


In post I have discussed about the JAVA program to find area of scalene triangle
Actually we have used the Heron's formula. 

According to that fomula if a, b,c be the three sides of a triangle, then the area of that triangle will be equal to the square root of [ s(s-a)*(s-b)*(s-c) ], where s= (a+b+c)/3.

-----------------------------------------------------------------------------------------------
class Scalene
{
public static void main(float x,float y,float z)
{
float s=(x+y+z)/2;
System.out.println(Math.sqrt(s*(s-x)*(s-y)*(s-z)));
}
}

Output:-   2 2 2
              1.7320508075688772

-------------------------------------------------------------------------------------------------

Just copy paste the code into the class file of Bluej compiler. Change the class name according to your's.
Thanks for visting Programming in JAVA
Happy Coding !!


No comments:

Powered by Blogger.