This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Recursion Reverse String

 
George Han
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently doing an assignment for my Java Class and our teacher said not to use CharAt() I know how to do it with it, but so far All i got is this can someone point me to the right direction?


class StringReverser {

public static void main(String args[]){
String LOL = "HI";
System.out.println(Reverse(LOL, 0));
}

public static String Reverse(String X, int CurrentValue){
if(X.length() = 1){
return X;
}
if(X.length() <= 0){
return "You gave me NOTHING!";
}
if(X.length() >1){
if(CurrentValue < X.length()){
char x = X.substring((X.length() - CurrentValue - 1), (X.length() - CurrentValue));

returnReverse(X,(CurrentValue + 1)) + x;
}

}

}
}
 
George Han
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nevermind I fixed it on my own.
 
paul wheaton
Trailboss
Pie
Posts: 21742
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose the reverse() method in StringBuffer would have been a form of cheating?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic