Reverse a String using Recursion

Objective: Given a String, write a recursive program to reverse it.

Example:

Original String: tutorial horizon
Reversed String: noziroh lairotut

Approach:

  • Take the first character out of the string, add it to the end of result of the remaining string.
  • Make a recursive call to remaining string.

Java Code:

Output:

Original String: tutorial horizon
Reversed String: noziroh lairotut

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: