Java Program to Reverse a String using Recursion - The Coding Shala

Home >> Java Programs >> Reverse a String using Recursion

 In this post, we will learn how to Reverse a String in Java using Recursion.

Java Program to Reverse a String using Recursion

Given a string S as input. You have to reverse the given string using Recursion.

Example 1:
Input: Akshay
Output: yahskA

Java Program: 

// Java program to Reverse a String using Recursion

public class Main {
	public static String reverseIt(String str) {
		if(str.length() == 0) {
			return "";
		return reverseIt(str.substring(1)) + str.charAt(0);
	public static void main(String[] args) { 
		String str = "Akshay Saini";
		String reverseStr = reverseIt(str);
		System.out.println("Reverse String is: " + reverseStr);

Other Posts You May Like
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.


Popular Posts from this Blog

Shell Script to find sum, product and average of given numbers - The Coding Shala

Single Number 3 LeetCode Solution - The Coding Shala

LeetCode - Number of Good Pairs Solution - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

Java Method Overloading - The Coding Shala