recursion - How to convert an iterative method into a recursive method (Java) -



recursion - How to convert an iterative method into a recursive method (Java) -

i working through java course of study on own, don't have answers of problems. problem unit one, based on karel++, stumped me. there robot object on pile of "beepers" , needs determine how many in pile , homecoming value. need convert next iterative method recursive method.

public int numofbeepersinpile() { int count = 0; while(nexttoabeeper()) { pickbeeper(); count++; } homecoming count; }

can give me hint?

public int numofbeepersinpile() { if (nexttobeeper()) { pickbeeper(); homecoming 1 + numofbeepersinpile(); } homecoming 0; }

java recursion karel

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -