-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseString.java
More file actions
27 lines (24 loc) · 797 Bytes
/
Copy pathReverseString.java
File metadata and controls
27 lines (24 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Week10.Tuto;
/**
*
* @author szeyu
*/
public class ReverseString {
public static String reverseString(String str, int index, StringBuilder reverseStr){
if(index < 0){
return reverseStr.toString();
}
reverseStr.append(str.charAt(index));
return reverseString(str, index-1, reverseStr);
}
public static String reverseString(String str){
return reverseString(str, str.length()-1, new StringBuilder());
}
public static void main(String[] args) {
System.out.println(reverseString("String"));
}
}