Skip to content

Commit 8c67174

Browse files
committed
Solution to write a Program to reverse a String
1 parent e5528d7 commit 8c67174

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎src/Resursion/ReverseAString.java‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package Resursion;
2+
3+
public class ReverseAString {
4+
public static void main(String[] args) {
5+
6+
String string = "pradeep";
7+
reverseString(string,0,string.length()-1);
8+
// System.out.println(reverseString);
9+
}
10+
11+
static void reverseString(String string, int startIndex, int endIndex){
12+
if (startIndex >= string.length()){
13+
return;
14+
}
15+
16+
System.out.println(string.charAt(endIndex));
17+
18+
reverseString(string,startIndex+1,endIndex-1);
19+
}
20+
21+
// static String reverse(String string, String reversedString){
22+
//
23+
// if (string.length() <= 1){
24+
// reversedString = reversedString + string.charAt(string.length()-1);
25+
// }
26+
// else{
27+
// reversedString = reversedString + string.charAt(string.length()-1);
28+
// reverse(string.substring(0,string.length()-1), reversedString);
29+
// }
30+
//
31+
// return reversedString;
32+
// }
33+
}

0 commit comments

Comments
 (0)