Counting the length of a string recursively
I'd appreciate any help with this, I've been working on a series of recursive problems all night and am pretty sure my brain has melted at this point, because I'm not even registering what I've typed any more. Recursion breaks my brain.
Code:
public static int Six(String s) {
if(s.equals("")){
return 0;
}
else{
return 1 + Six(s);
}
}
Unfortunately this results in an overflow and I'm not entirely sure why. Any help? Thanks in advance!
Re: Counting the length of a string recursively
I believe you program will run a never ending loop. As the string that calling back to the Six() method is never changed. I will only stop when the JVM is run out of memory.