求求各路大神,如何解答此题

 

此题主要问题是只给了三边长,所以只能套用海伦公式求面积,

如有帮助,请在我的回答上点击【采纳】,谢谢!

package com.ht.servlet;

public class Triangle {
	double x,y,z;

	public Triangle(float x, float y, float z) {
		super();
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	//判断是否三角形
	public boolean isSJ(){
		if(x+y>z||x+z>y||y+z>x){
			return true;
		}
		return false;
	}
	
	
	public double getArea(){
		double mj=0;
		if(isSJ()){
			//由于只给了三条边,套用海伦公式
			double p=(x+y+z)/2;//半周长
			 mj =Math.sqrt(p*(p-x)*(p-y)*(p-z)) ;
		}else{
			System.out.println("输入的三条边不能构成三角形!");
		}
		return mj;
	}
	
	public static void main(String[] args) {
		Triangle tr = new Triangle(7, 8, 9);
		System.out.println("面积是:  "+tr.getArea());
	}
}

 

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632