-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAreaOfTriangle.java
More file actions
35 lines (21 loc) · 923 Bytes
/
AreaOfTriangle.java
File metadata and controls
35 lines (21 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;
public class AreaOfTriangle{
public static void main(String[]args){
Scanner input = new Scanner(System.in);
double x1, y1, x2, y2, x3, y3;
System.out.println("Enter the sides of the triangle: x1, y1, x2, y2, x3, y3 ");
x1 = input.nextDouble();
y1 = input.nextDouble();
x2 = input.nextDouble();
y2 = input.nextDouble();
x3 = input.nextDouble();
y3 = input.nextDouble();
double side1 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
double side2 = Math.sqrt(Math.pow(x3 - x2, 2) + Math.pow(y3 - y2, 2));
double side3 = Math.sqrt(Math.pow(x1 - x3, 2) + Math.pow(y1 - y3, 2));
double s = (side1 + side2 + side3) / 2;
double sides = s * ((s - side1) * (s - side2) * (s - side3));
double area = Math.sqrt(sides);
System.out.printf("The area of the triangle is %.1f%n", area);
}
}