wood burning stoves 2.0*
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
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: 20494

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

permaculture Wood Burning Stoves 2.0 - 4-DVD set
It is sorta covered in the JavaRanch Style Guide.
subject: Recursion Reverse String
Similar Threads
Help with simple Recursive functions
Can anyone explain this code from ...Java 2 Part-1 the programmers exam - page 49
Array Reference Problem....
let me know about the logic here