LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 477 users online 225384 members 791 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
marshmellowman
and victorious in war shall be made glorious in peace...
Mood: Scheming
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
7 online / 16 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Adding Reply

Adding Reply
Archived Topic: It will not be bumped to the top of the forum.
Topic wtf...java
Membername   Not a member? Sign Up Free (takes 20 seconds)
Password   Forgotten your password?
Post

Font:   Size:   Color:

FAQ Keyword Search:
Post Options
Favorites Manager
Notify me of new replies to this topic by email
Notify me of new replies to this topic by private message
Original Post
matto Posted at 8:04 pm on Nov. 12, 2008
So I'm doing this problem, and I've entered the code:
Code:
public int strDist(String str, String sub) {
 if( str.length()==0 ) return 0;
 if( !(str.substring(0, sub.length()).equals(sub)) ) {
   return strDist( str.substring(1, str.length()), sub);
 }
 if( !( str.substring( str.length()-sub.length(), str.length()).equals(sub) ) ) {
   return strDist( str.substring(0, str.length()-1), sub);
 }
 return str.length();
}
And it passes all the tests except "other tests," which isn't useful since I don't know what's causing it to break.  Any ideas?  This is not kewl.  :(

Replies
matto Posted at 8:49 pm on Nov. 12, 2008
o snap alright.  thanks.  that's a useful method....
h a t t Posted at 8:40 pm on Nov. 12, 2008
just added

if (str.indexOf(sub) == -1 ) return 0;

to the top and it works
(when the index is -1 it means that the string is nowhere to be found)

h a t t Posted at 8:35 pm on Nov. 12, 2008
ah. it fails if the string doesn't contain the other string anywhere.
matto Posted at 8:32 pm on Nov. 12, 2008
yawtf.  I'm trying to come up with a situation that'd cause it to fail... can't think of anything.
h a t t Posted at 8:30 pm on Nov. 12, 2008
well i ran it in eclipse and it got the results it was looking for so i don't know what the X is about.
Majo Posted at 8:09 pm on Nov. 12, 2008
I wish I understood that but Java I kicked my ass, sorry.
bratalvarado Posted at 8:08 pm on Nov. 12, 2008
wait what is this about
glowinthedark Posted at 8:06 pm on Nov. 12, 2008
i thought this was about coffee..

dang it!

All 8 previous replies displayed.