Okay so I have an assignment to determine how long will it take to a monkey to climb a pole of x height. If ascends 10 ft. in 10 minutes and slips down 3 in 10 min while resting. When it reaches the top of the pole it stops, and climbs one feet per minute. This using recurssion, and my method is right so far, but I'm getting stack overflow and I do not know how to avoid it so im freakin out, any idea?
Thanks guys
public static long climb(long height, long time) { //Recursive method
if (height <= 0) //base case
return time;
/*Every 10 min add 3 to height (notice im doing it backwards,
instead of substracting 3.
I find it easier to deal with this way and easier to implement the base case) *//
else if (time != 0 && time % 10 == 0) {
return climb(height+3, time+10);
}
else {
return climb(height-1, time+1);
} } }