A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
Recursion Reverse String
George Han
Greenhorn
Joined: Aug 17, 2005
Posts: 17
posted
Nov 17, 2005 20:51:00
0
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
posted
Nov 17, 2005 21:02:00
0
nevermind I fixed it on my own.
paul wheaton
Trailboss
Joined: Dec 14, 1998
Posts: 19672
∞
I like...
posted
Nov 17, 2005 21:08:00
0
I suppose the reverse() method in
StringBuffer
would have been a form of cheating?
permaculture forums
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: Recursion Reverse String
Similar Threads
Can anyone explain this code from ...Java 2 Part-1 the programmers exam - page 49
Help with simple Recursive functions
Array Reference Problem....
let me know about the logic here
ArrayList
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter