程序如何实现

解决方案 »

  1.   

    判断这三个数中是否有两个相等的,如果没有肯定不行,返回false;如果有,判断这两个相等的数的和是否大于另外一个数,如果大于,则可以,返回true;如果小于等于,则不行,返回false。
      

  2.   

    public class  Test
    {
    public static void main(String[] args) 
    {
    int a=0,b=0,c=0;
    try
    {
    a=new Integer(args[0]).intValue();
    b=new Integer(args[1]).intValue();
    c=new Integer(args[2]).intValue();
    System.out.println("输入的三边为:"+a+","+b+","+c);
    System.out.println("是否能构成等腰三角形:"+isIsoscelesTriangle(a,b,c));
    }
    catch (NumberFormatException e)
    {
    //输入的参数有非数字格式,比如字符
    System.err.println("请输入正确的数字!");
    }
    catch(ArrayIndexOutOfBoundsException e)
    {
    //输入的参数不足3个
    System.err.println("至少要输入三个数字作为参数!");
    }
    }
    public static boolean isIsoscelesTriangle(int a,int b,int c)
    {
    boolean result=true;
    if(a!=b)
    {
    if(a!=c)
    {
    if(b!=c)
    {
    result=false;
    }
    else
    {
    result=(2*b>a)?true:false;
    }
    }
    else
    {
    result=(2*a>b)?true:false;
    }
    }
    else
    {
    result=(2*a>c)?true:false;
    }
    return result;
    }
    }