forked from RasPat1/practice-codewars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSortContent.java
29 lines (26 loc) · 884 Bytes
/
SortContent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
public class SortContent {
public static String sortTheInnerContent(String words) {
String[] wordArr = words.split(" ");
String[] solution = new String[wordArr.length];
int i = 0;
for (String word: wordArr) {
if (word.length() > 3) {
String sortedWord = word.substring(1, word.length() - 1);
char[] sortedChars = sortedWord.toCharArray();
Arrays.sort(sortedChars);
for (int j = 0; j < sortedChars.length / 2; j++) {
char tmp = sortedChars[j];
int index = sortedChars.length - 1 - j;
sortedChars[j] = sortedChars[index];
sortedChars[index] = tmp;
}
solution[i] = word.charAt(0) + new String(sortedChars) + word.charAt(word.length() - 1);
} else {
solution[i] = word;
}
i++;
}
return String.join(" ", solution);
}
}