Results 1 to 2 of 2
- 11-29-2012, 03:33 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 8
- Rep Power
- 0
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.
Unfortunately this results in an overflow and I'm not entirely sure why. Any help? Thanks in advance!Java Code:public static int Six(String s) { if(s.equals("")){ return 0; } else{ return 1 + Six(s); } }
- 11-29-2012, 03:37 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 697
- Rep Power
- 6
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.
Website: Learn Java by Examples
Similar Threads
-
Recursively searching a string
By fam2315 in forum New To JavaReplies: 0Last Post: 10-13-2012, 06:25 PM -
how to compare one string with another dynamic length pattern string?
By ravi.josih53 in forum New To JavaReplies: 11Last Post: 08-15-2011, 10:12 AM -
String.length?
By rizowski in forum New To JavaReplies: 7Last Post: 11-20-2010, 05:33 PM -
string length HELP PLZ!!
By vette427 in forum EclipseReplies: 1Last Post: 09-23-2010, 06:12 AM -
Recursively listing files in a directory accepted as a string??
By Zxcvtypo in forum New To JavaReplies: 8Last Post: 11-20-2009, 09:33 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks