Java Program to Reverse a String using Recursion - The Coding Shala
Home >> Java Programs >> Reverse a String using Recursion
Other Posts You May Like
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); } }
- How to Reverse a String in Java
- Java Program to Find Duplicate characters count in a String
- Java Program to Compare two Strings without whitespaces
- Java Program to Count Negative Numbers in Sorted Matrix
- Java Program to Find Sum of N numbers
Comments
Post a Comment