三解形的面积

来源:互联网 发布:织梦cms管理 编辑:程序博客网 时间:2024/05/16 14:47
1-2计算三角形的面积。输入三角形的三个点(x1,y1),(x2,y2)和(x3,y3),计算三解形的面积。(1)程序代码如下:package cn.edu.jxufe.denghuan;import java.util.Scanner;public class TriangleArea {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();//Math.pow(a, b)返回值为a的b次幂;double a=Math.pow(x1-x2,2)+Math.pow(y1-y2,2);double side1=Math.pow(a, 0.5);double b=Math.pow(x1-x3,2)+Math.pow(y1-y3,2);double side2=Math.pow(b, 0.5);double c=Math.pow(x2-x3,2)+Math.pow(y2-y3,2);double side3=Math.pow(c, 0.5);double s=(side1+side2+side3)/2;double area=Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));System.out.println("The area of the triangle is "+(int)(area*10)/10.0);}}

0 0
原创粉丝点击