Witam,
Robie małe zadanka z Javy i przy jedny z nich mam problem. Na wejściu dostaję Strina
String s = "hSgdHQ\nHnDMao\nClNNxX\niRvxxH\nbqTVvA\nwvSyRu";
Na wyjściu chcę dostać coś takiego:
String r = "QHdgSh\noaMDnH\nXxNNlC\nHxxvRi\nAvVTqb\nuRySvw";
Aktualnie odwracam wartości pomiędzy "\" lecz nie wyglądają tak jakbym chciał czyli:
uRySvw
AvVTqb
HxxvRi
XxNNlC
oaMDnH
QHdgSh
Mój kod:
public static String mirror(String string) {
String result = "";
char[] tab = string.toCharArray();
int right = tab.length - 1 ;
for(int left = 0; left < right; left++, right--){
char temp = tab[left];
tab[left] = tab[right];
tab[right] = temp;
}
for(char c : tab){
result += c;
}
return result;
}