缺少返回语句制作三角形程序

2022-01-19 00:00:00 return java
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.");        

        }
    } // missing return statement here error

我正在制作一个确定三角形的程序.这是我在编译时遇到错误的地方.它在最后给出了一个缺少的返回语句.如何解决这个问题?

I'm making a program that determines triangles. This is where I'm getting my error When I compile this. It gives an missing return statement at the end. How would fix 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.";        

        }
                        }
  else{
     return "Not a triangle";
      }
  }

相关文章