21. JAVA Program To find Area of Triangle.
How does this program work?
- In this program you are going to learn about How to find out the Area of triangle if 3sides are given java.
- Take User inputs for lengths of 3sides of a triangle.
- And Store them in variables to find out the final answer and display it using java.
Here is the code
// Area of a triangle with 3 sides
import java.util.Scanner;public class Side
{
public static void main(String args[])
{
double a,b,c,s,area;
System.out.println("Enter the 1st side of the triangle\n");
Scanner obj1=new Scanner(System.in);
a=obj1.nextDouble();
System.out.println("Enter the 2nd side of the triangle\n");
b=obj1.nextDouble();
System.out.println("Enter the 3rd side of the triangle\n");
c=obj1.nextDouble();
/* compute s */
s=(a+b+c)/2;area=Math.sqrt(s*(s-a)*(s-b)*(s-c));
System.out.println("Area of a triangle is :"+area );
}
}