forked from mayankgb2/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverse
More file actions
21 lines (16 loc) · 437 Bytes
/
Reverse
File metadata and controls
21 lines (16 loc) · 437 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class JavaReverseString {
public static void main(String[] args) {
System.out.println(reverseString("abc"));
System.out.println(reverseString("123!@#098*"));
}
public static String reverseString(String in) {
if (in == null)
return null;
StringBuilder out = new StringBuilder();
int length = in.length();
for (int i = length - 1; i >= 0; i--) {
out.append(in.charAt(i));
}
return out.toString();
}
}