Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

returning a value from recursive method: what's wrong with that?

807569Aug 2 2006 — edited Aug 2 2006
acme is the name of the "factory" i had to implement.
the problem is: it runs correctly, however returning always null
what to fix?

this is the piece of code:
/**
* independent
*
* returns the department with the given name
*
* Hint for implementation: define a recursive helper method.
*/
private Department independent(String departmentName){
return(helper (m_acme,departmentName));
}

/**helper procedure for findDepartment
*
* @param rootdep
* @param departmentName
* @return the deparment with the given name
*
*/
private Department helper (Department rootdep, String departmentName) {
String s = rootdep.getName();
if (s.equals(departmentName)) {return rootdep;}
else
for (int i = 0; i < rootdep.getSubDepartments().length; i++) {
helper(rootdep.getSubDepartments(),departmentName);
}
return null;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 30 2006
Added on Aug 2 2006
4 comments
326 views