aspose file tools*
The moose likes Beginning Java and the fly likes Error states: This method must return a result of type int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error states: This method must return a result of type int" Watch "Error states: This method must return a result of type int" New topic
Author

Error states: This method must return a result of type int

Chetan Graham
Greenhorn

Joined: Dec 01, 2007
Posts: 21
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

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41809
    
  62
Hello Chetanji-

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).


Ping & DNS - my free Android networking tools app
Chetan Graham
Greenhorn

Joined: Dec 01, 2007
Posts: 21
Thanks for setting me straight on the Name Display. That was the name all my friends call me where I work and at home.

I thought I had closed up all the holes in the program, but obviously not.
Here is what I added at the top of the program and I still get the same error message. What am I missing?

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14144
    
  18

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Chetan Graham
Greenhorn

Joined: Dec 01, 2007
Posts: 21
Thank you Jesper Young,
I am humbled by my obvious blindness.
Blessings,
Chetanji
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error states: This method must return a result of type int