Java语言程序设计基础篇编程练习题2.19示例代码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38234015/article/details/88362037
import java.util.Scanner;
public class Test2_19 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.print("Enter three points for a triangle: ");
		double x1 = input.nextDouble();
		double y1 = input.nextDouble();
		double x2 = input.nextDouble();
		double y2 = input.nextDouble();
		double x3 = input.nextDouble();
		double y3 = input.nextDouble();
		input.close();
		
		double s1 = Math.pow(Math.pow((x2 - x1),2) + Math.pow((y2 - y1),2), 0.5);
		double s2 = Math.pow(Math.pow((x2 - x3),2) + Math.pow((y2 - y3),2), 0.5);
		double s3 = Math.pow(Math.pow((x3 - x1),2) + Math.pow((y3 - y1),2), 0.5);
		double s = (s1 + s2 + s3) / 2;
		
		double area = Math.pow(s * (s - s1) * (s - s2) * (s - s3), 0.5);
		System.out.println("The area of the triangle is " + area);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_38234015/article/details/88362037