Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.

Commit 182c8f1

Browse files
author
Ahmed Tawila
committed
reverse a String
1 parent 74462be commit 182c8f1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package javarevisited.top.fifty.java.programs.from.coding.interviews;
2+
3+
public class ReverseAString {
4+
5+
public static String reverseString(String s) {
6+
String result = "";
7+
for (int i = 0; i < s.length(); i++) {
8+
result += s.charAt(s.length() - i - 1);
9+
}
10+
return result;
11+
}
12+
13+
public static void main(String[] args) {
14+
String test = "To be reversed!";
15+
System.out.println(reverseString(test));
16+
}
17+
}

0 commit comments

Comments
 (0)