This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 20271
    ∞

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: http://aspose.com/file-tools
 
subject: Recursion Reverse String
 
Similar Threads
Help with simple Recursive functions
let me know about the logic here
Array Reference Problem....
Can anyone explain this code from ...Java 2 Part-1 the programmers exam - page 49
ArrayList