Error states: This method must return a result of type int
Joined: Dec 01, 2007
Hello to All, I've would like to see if this coding runs the Ackerman function. I'm not understanding why I keep getting this error. Sure it is just a beginner's mistake. I've run many other math class projects, this one has me scratching my head. Blessings, Chetanji
Joined: Mar 22, 2005
Welcome to JavaRanch.
On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.
As to your question, the method must return a result for all branches of execution. As it is, there are some branches that would reach the end of the method without having encountered a "return" statement. Thus, there would not be a result to return; this is not allowed. One case would be if m < 0. You might want to return something indicating an error in those cases (like a -1).
You get this error because there is a possibility that the execution gets at a spot where there the method ends but there is no "return" statement. Since you specified that the method returns int, there must be a "return" statement at all possible execution paths where the method ends.
Look at the third if-statement: if ((m > 0) && (n > 0))
That one has no else-statement. If the condition is false, then you get to a point where you're not returning a value.