Skip to content

Commit 7b0ffb1

Browse files
committed
Reversing the string using recursion
1 parent df20459 commit 7b0ffb1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

reverse string.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.io.*;
2+
class stringreverse
3+
{
4+
String reverseString(String str)
5+
{
6+
String reverse=" ";
7+
if(str.length()==1)
8+
{
9+
return str;
10+
}
11+
else
12+
{
13+
reverse=reverse+str.charAt(str.length()-1)+reverseString(str.substring(0,str.length()-1));
14+
return reverse;
15+
}
16+
}
17+
public static void main(String args[])
18+
{
19+
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
20+
System.out.println("Enter the string");
21+
String srr=br.readLine();
22+
System.out.println("Reverse="+reverseString(srr));
23+
}
24+
}
25+

0 commit comments

Comments
 (0)