-1
   public static String triangleCheck(){ // Triangle Method
      Scanner scan = new Scanner(System.in);
      
            System.out.print("What is the length of side 1? ");
            int side1 = scan.nextInt();
            System.out.print("what is the length of side 2? ");
            int side2 = scan.nextInt();
            System.out.print("What is the length of side 3? ");
            int side3 = scan.nextInt();

      if (!(side1+side2>side3 && side2+side3>side1 && side3+side1>side2))
         return " However your measure don't quite make a full triangle. ";
         
      else if ((side1 > side2) && (side1 > side3))
         if(side1*side1 == side2*side2 + side3*side3)
            return "It is a right triangle.";
         else if((side1*side1) > side2*side2 + side3*side3)
            return "It is an obtuse triangle.";
         else 
            return "It is an acute triangle.";
            
      else if ((side2 > side1) && (side2 > side3))
         if(side2*side2 == side1*side1 + side3*side3)
            return "It is a right triangle.";
            else if((side2*side2) > side1*side1 + side3*side3)
               return "It is an obtuse triangle.";
         else 
            return "It is an acute triangle.";
      
      else if ((side3 > side1) && (side3 > side2))
            if (side2*side2 == side1*side1 + side3*side3)
               return "It is a right triangle.";
            else if((side2*side2) > side1*side1 + side3*side3)
               return "It is an obtuse triangle.";
            else 
               return "It is an acute triangle.";
}

This is my method for my program I'm trying to run my code but it won't run it says error: missing return statement "}", I think this if/else part is the problem but I can't figure out where I did wrong and how I could fix it

Matt Vickery
  • 121
  • 1
  • 8
  • 1
    What do you expect to return if **none** of the if / else-if statements is true? – azurefrog Dec 07 '21 at 17:56
  • 1
    Consider adding curly braces (even for a one-liner block), which will clarify the code structure, and make it more obvious what is missing. – Andrew S Dec 07 '21 at 18:03

1 Answers1

3

At the end of all your if/else conditions, add a final else to handle invalid input.

...
else {
    return "Error: Unable to check triangle.";
}
Stack Underflow
  • 2,363
  • 2
  • 26
  • 51