write a recursive method that accepts a single String as a parameter and returns the reverse of that String. For example, calling the method reverse("Test would return the String "tesT".
any suggestion?
Thanks in advance
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
write a recursive method that accepts a single String as a parameter and returns the reverse of that String. For example, calling the method reverse("Test would return the String "tesT".
any suggestion?
Thanks in advance
String example = "Hello, World!"; System.out.println( (new StringBuffer(example)).reverse() );
That should get you goingYou will need imports etc too hehe xD
P.S Sorry for the slow reply
Regards,
Chris
hi,
wlecome to the java prog forums.
here is the code: http://www.javaprogrammingforums.com...e-program.html
above is the sample code.
Cheers.
Truffy![]()
Last edited by Truffy; June 14th, 2009 at 09:37 PM.
Public String someMethod(String input) { String output=""; Char[] reverse=new Char[input.length()]; reverse=input.tochararray(); for(int i=input.length();i>=0;i--) { output+=Character.toString(reverse[i]) } return output; }
keep in mind this is a skeleton method and most likely doesn't work due to the fact Im not in front of an IDE to test this out in. i just wanted you to get the idea. Oh this is not recursive btw.(sorry).
Last edited by Fendaril; June 14th, 2009 at 11:02 PM. Reason: mistake.