您的位置:首页 > 其它

课后习题page101.pp3.7

2017-10-07 22:24 148 查看
//************************************************
// triangleArea.java  Author: Jayson
//***********************************************

import java.util.Scanner;

public class triangleArea
{
//--------------------------------------------------
//  input triangle's three side, and
//  output its area with Heron Formula
//  Heron Formula: area = sqrt(s(s-a)(s-b)(s-c)
//  s = (a+b+c) / 2
//--------------------------------------------------
public static void main(String[] args)
{
double a, b, c, s, area;
Scanner scan = new Scanner(System.in);

System.out.println("Please input three side of a triangle: ");
a = scan.nextDouble();
b = scan.nextDouble();
c = scan.nextDouble();
scan.close();

s = (a + b + c) /2 ;
area = Math.sqrt(s * (s-a) * (s-b) * (s-c));

System.out.println("The area of the triangle is: " + area);
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: