0% found this document useful (0 votes)
21 views

Triangle

This Java code defines a Triangle class that calculates the area of a triangle given the x and y coordinates of its three vertices by computing the lengths of its three sides and applying the Heron's formula.

Uploaded by

Mr. X
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Triangle

This Java code defines a Triangle class that calculates the area of a triangle given the x and y coordinates of its three vertices by computing the lengths of its three sides and applying the Heron's formula.

Uploaded by

Mr. X
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

public class Triangle {

public static void main(String[] args){


double x1 = 1.5;
double y1 = -3.4;
double x2 = 4.6;
double y2 = 5;
double x3 = 9.5;
double y3 = -3.4;
double side1,side2,side3,s,area;
side1 = Math.sqrt(Math.pow((x1-x2),2)+ Math.pow((y1-y2),2));
side2 = Math.sqrt(Math.pow((x2-x3),2)+ Math.pow((y2-y3),2));
side3 = Math.sqrt(Math.pow((x3-x1),2)+ Math.pow((y3-y1),2));
s = (side1+side2+side3)/2;
area = Math.round(Math.sqrt(s*(s-side1)*(s-side2)*(s-
side3))*100.0)/100.0;
System.out.println(" The total area = " + area);}}

You might also like