用Java描述一个三角形,提供计算三角形面积方法.三角形的三个边长从键盘输入.

问题描述:

用Java描述一个三角形,提供计算三角形面积方法.三角形的三个边长从键盘输入.

public class Js
{
private double a;
private double b;
private double c;
Js(double a,double b,double c)
{
this.a = a;
this.b = b;
this.c = c;
}
public double getA()
{
return a;
}
public double getB()
{
return b;
}
public double getC()
{
return c;
}
public double area()
{
double s1=(a+b+c)/2;
double s2 = s1*(s1-a)*(s1-b)*(s1-c);
double result = Math.sqrt(s2);
return result;
}
}
class Jxcomputer
{
public static void main(String[] args)
{
Js js = new Js(3,6,8);
System.out.println("三角形三边长度分别为:"+"a:"+js.getA()+"\tb:"+js.getB()+"\tc:"+js.getC());
System.out.println("三角形面积为:"+js.area()); }
}