import java.util.Scanner;
class NotRectangleException extends Exception
{
public NotRectangleException(String msg)
{
super(msg);
}
}
class MyRectangle
{
private float x;
private float y;
private float z;
public MyRectangle()
{
}
public MyRectangle(float a, float b, float c)
{
x = a;
y = b;
z = c;
}
public void getArea()
{
try{
isRect();
}catch(NotRectangleException ne){
System.out.println("自扒者定义异常类:" + ne.getMessage());
return;
}
float p = (x + y + z)/2.0f;
System.out.println("三角形的面积: " + Math.sqrt(p*(p-x)*(p-y)*(p-z)) + "(单位)");
}
public void showInfo()
{
try{
isRect();
System.out.println("三角形的三边分别为:x = " + x + " y = " + y + " z = " + z);
}catch(NotRectangleException ne){
System.out.println("自定义异常类:" + ne.getMessage());
}
}
public boolean isRect() throws NotRectangleException
{
if(x+y>z && x+z>y && y+z>x)
{
return true;
}
else {
throw new NotRectangleException("x = " + x + ",y = " + y + ",z = " + z + "不能构成三角形!\n");
}
}
}
public class MyRectangleTest
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("请输简伏入三角形的春咐薯三条边:");
float a = scan.nextFloat();
float b = scan.nextFloat();
float c = scan.nextFloat();
MyRectangle mr = new MyRectangle(a, b, c);
System.out.println("\n若三条边能组成的三角形->则面积: ");
mr.getArea();
System.out.println("\n显示三条边的信息: ");
mr.showInfo();
}
}
数学中能构成三角形的提案件是什么
就是任意两边之长的和必须大于第三边
根据这些条件你写一些if语句做下判断就可以枯消春没耐了
具体的我就不写桥毕了