Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Any suggestions on making this code work?

 
michael bradly
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am recieving this error message...
C:\JavaEx\methodTest\methodTest.java:4: missing return statement
{
Essentially I am using a recursive method to return a max value by dividing an array in half, searching each half for the maximum, then resolving which half has the max number.

[ September 14, 2002: Message edited by: michael bradly ]
[ September 14, 2002: Message edited by: michael bradly ]
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use the UBB "CODE" tag to reformat your code, so that indentation is preserved. My guess is that there's at least one path through that function that doesn't end at a return statement. Since the function returns int, all possible execution paths (that don't throw an exception) must end at a return statement.
 
michael bradly
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I've resolved the problem I was having by making the base case
if (first == last)
{
return anArray[0];
}
else ...
So far it is working out in my testing.
Originally posted by Ron Newman:
Please use the UBB "CODE" tag to reformat your code, so that indentation is preserved. My guess is that there's at least one path through that function that doesn't end at a return statement. Since the function returns int, all possible execution paths (that don't throw an exception) must end at a return statement.

[ September 14, 2002: Message edited by: michael bradly ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic