-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a program to Reverse a String
Created a Program to Reverse a String Using Recursion in Java
- Loading branch information
1 parent
3810a4e
commit fb42a26
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
public class ReverseString{ | ||
public String reverseString(String str){ | ||
if(str.isEmpty()){ | ||
System.out.println("String is empty.") ; | ||
return str; | ||
} | ||
else{ | ||
return reverseString(str.substring(1))+str.charAt(0); | ||
} | ||
} | ||
public static void main(String[] args){ | ||
ReverseString rs = new ReverseString(); | ||
String resultantSting1 = rs.reverseString("SHAKEEL"); | ||
String resultantSting2 = rs.reverseString("AHMED"); | ||
String resultantSting3 = rs.reverseString("MUET"); | ||
System.out.println(resultantSting1); | ||
System.out.println(resultantSting2); | ||
System.out.println(resultantSting3); | ||
} | ||
} |