This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Recursion Reverse String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Recursion Reverse String" Watch "Recursion Reverse String" New topic

Recursion Reverse String

George Han

Joined: Aug 17, 2005
Posts: 17
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

Joined: Aug 17, 2005
Posts: 17
nevermind I fixed it on my own.
paul wheaton

Joined: Dec 14, 1998
Posts: 20861

I suppose the reverse() method in StringBuffer would have been a form of cheating?

permaculture Wood Burning Stoves 2.0 - 4-DVD set
I agree. Here's the link:
subject: Recursion Reverse String
It's not a secret anymore!