Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d29f62d

Browse files
Create ReverseString.java
1 parent b47cafa commit d29f62d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎src/ReverseString.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class ReverseString {
2+
3+
public static void main(String[] args) {
4+
5+
String str = "789";
6+
System.out.println(reverseString(str));
7+
}
8+
9+
public static String reverseString(String in) {
10+
if (in == null)
11+
throw new IllegalArgumentException("input null");
12+
13+
StringBuilder out = new StringBuilder();
14+
15+
char[] chars = in.toCharArray();
16+
17+
for (int i = chars.length - 1; i >= 0; i--)
18+
out.append(chars[i]);
19+
20+
return out.toString();
21+
}
22+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /