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

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

作者:互联网

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);
	}
}

 

标签:练习题,Java,示例,double,0.5,nextDouble,pow,input,Math
来源: https://blog.csdn.net/qq_38234015/article/details/88362037