Missing return statement making triangle program

后端 未结 4 599
花落未央
花落未央 2021-01-27 09:24
public String displayType(int side1, int side2,int side3)
    {
        if(( side1+side2 > side3))

            if(( side1==side2) && (side2==side3))//tell if         


        
4条回答
  •  误落风尘
    2021-01-27 09:44

    Compiler is saying that You have to return something,because if all your IF conditions fail then what will it do?

    you can do like this:

    public String displayType(int side1, int side2,int side3)
    {
        if(( side1+side2 > side3))
    
            {
    if(( side1==side2) && (side2==side3))//tell if equalateral
            {
                return ("Equalateral Triangle.");
            }
            else if (( side1==side2) & (side2 != side3) || (side1 == side3) & (side3 != side1))//tells if isosceles
            {
                return ("Isosceles Triangle.");
            }
            else if ((side1 != side2) & (side2 != side3))//tells if scalene
            {
                return ("Scalene Triangle.");        
    
        }
    return ("It is not a triangle");
    } // missing return statement here error
    

提交回复
热议问题