HW2.21

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8 
 9         System.out.print("Enter three points for a triangle: ");
10         double x1 = input.nextDouble();
11         double y1 = input.nextDouble();
12         double x2 = input.nextDouble();
13         double y2 = input.nextDouble();
14         double x3 = input.nextDouble();
15         double y3 = input.nextDouble();
16 
17         input.close();
18 
19         double side1Square = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
20         double side1 = Math.pow(side1Square, 0.5);
21         double side2Square = (x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1);
22         double side2 = Math.pow(side2Square, 0.5);
23         double side3Square = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
24         double side3 = Math.pow(side3Square, 0.5);
25 
26         double s = (side1 + side2 + side3) / 2;
27         double areaSquare = s * (s - side1) * (s - side2) * (s - side3);
28         double area = Math.pow(areaSquare, 0.5);
29         System.out.println("The area of the triangle is " + area);
30     }
31 }

 

转载于:https://www.cnblogs.com/wood-python/p/5750843.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值