This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates 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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Recursion Reverse String" Watch "Recursion Reverse String" New topic
Author

Recursion Reverse String

George Han
Greenhorn

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
Greenhorn

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

Joined: Dec 14, 1998
Posts: 20660
    ∞

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


permaculture Wood Burning Stoves 2.0 - 4-DVD set
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Recursion Reverse String