Movatterモバイル変換


[0]ホーム

URL:


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

Commit841ca94

Browse files
committed
Add reverse string snippet
1 parent56118df commit841ca94

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Update the sample application with the snippet and add a test for it. After prov
1717
*[Factorial](#factorial)
1818
*[Fibonacci](#fibonacci)
1919

20+
###String
21+
*[Reverse string](#reverse-string)
22+
2023
##Array
2124

2225
###Generic two array concatenation
@@ -77,3 +80,15 @@ Update the sample application with the snippet and add a test for it. After prov
7780
```
7881

7982
[⬆ back to top](#table-of-contents)
83+
84+
##String
85+
86+
###Reverse string
87+
88+
```java
89+
publicstaticString reverseString(String s) {
90+
returnnewStringBuilder(s).reverse().toString();
91+
}
92+
```
93+
94+
[⬆ back to top](#table-of-contents)

‎src/main/java/Library.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,13 @@ public static int factorial(int number) {
6565
}
6666
returnresult;
6767
}
68+
69+
/**
70+
* Reverse string
71+
* @param s the string to reverse
72+
* @return reversed string
73+
*/
74+
publicstaticStringreverseString(Strings) {
75+
returnnewStringBuilder(s).reverse().toString();
76+
}
6877
}

‎src/test/java/LibraryTest.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,9 @@ public void testFactorial() {
7474
assertEquals(362880,Library.factorial(9));
7575
assertEquals(3628800,Library.factorial(10));
7676
}
77+
@Test
78+
publicvoidtestReverseString() {
79+
assertEquals("oof",Library.reverseString("foo"));
80+
assertEquals("ÖÄÅ321FED cba",Library.reverseString("abc DEF123ÅÄÖ"));
81+
}
7782
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp