三角形の面積の計算

  

●Triangle(double aa, double bb, double cc)

与えられた辺の長さの三角形を作成する。
  

●Triangleサンプル

class Triangle{
  private double a, b, c; public Triangle(){
    this.a = this.b = this.c = 1; }
    public Triangle( double aa, double bb, double cc ){
  this.a = aa; this.b = bb; this.c = cc; }
  public double getArea(){
    double s;
    double Area;
    s = ( this.a + this.b + this.c ) / 2.0;
    Area = Math.sqrt( s * (s-this.a) * (s-this.b) * (s-this.c) );
  return Area; }
}

class TriTest{
  public static void main(String args[]){
    Triangle T1, T2; T1 = new Triangle();
    T2 = new Triangle( 3,4,5 );
    System.out.println("最初の面積は" + T1.getArea() + "である" );
    System.out.println("次の面積は" + T2.getArea() + "である" );
  }
}

●実行結果

最初の面積は0.4330127018922193である
次の面積は6.0である