• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i got a different resolt than i was supposed to

 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried to follow this recurstion
but instead of getting the resolt i expected i got
some thing realy different

http://img185.imageshack.us/my.php?image=img8290nf7.jpg



i entered (2,abcd)
i was supposed to get


cd
bd
bc
ad
ac
ab

instead i got some other answer using this diagram
can you tell me where i got ot wrong??

[ February 14, 2008: Message edited by: donaldth smithts ]
[ February 14, 2008: Message edited by: donaldth smithts ]
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use copy-and-paste to quote code, so you don't get misprints like "Public."
Please tell us what you think the recursion should do and what it is actually doing. It is doing exactly what you have told it to do.
Please work out how you are supposed to get "ab" from "abcd" which is where you are having problems.
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have to take another look at your algorithm.
You want to display substrings, but you don't manipulate your input string at all (except for making it longer by adding numbers at the end). How do you want to get from "abcd" to "cd"?
 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are right

is there any code that prints the subsets of the string??
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you're asking for. If you're wanting a full solution to the problem, remember we are NotACodeMill.

If you're just asking how to get a substring of a string, you might consider String.substring() method.
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether you manipulate the string you send to the call or before you print it out, you might want to look at the String API and find what you need.

Particularly
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#substring(int,%20int)

might be useful
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic