Commit 3c1efc3
Changed files (2)
src/Q1/ReversedSentence.java
@@ -5,7 +5,11 @@ import java.util.Scanner;
public class ReversedSentence {
public static String change5thPosition(String s) {
- return "";
+ char[] result = new char[s.length()];
+
+ for (int i = 0; i < s.length(); i++) result[i] = (i > 0 && i % 5 == 0) ? 'z' : s.charAt(i);
+
+ return new String(result);
}
public static String printChar2DArray(char[][] arr) {
src/Q1/ReversedSentenceTest.java
@@ -30,4 +30,9 @@ public class ReversedSentenceTest extends TestCase {
assertEquals(
"lamb little a had mary", ReversedSentence.reverseByWord("mary had a little lamb"));
}
+
+ public void testChange5thPosition() {
+ assertEquals(
+ "mary zad azlittze lazb", ReversedSentence.change5thPosition("mary had a little lamb"));
+ }
}