标签:
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 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5750843.html