Solución
solution.tsTypeScript
public class Solution {
public String rot13(String text) {
List<String> abcMa = List.of(
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M","N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X","Y", "Z",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M","N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" );
List<String> abcMi = List.of(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m","n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m","n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" );
StringBuilder result = new StringBuilder();
for(char ca : text.toCharArray()){
int potition = 0;
if(Character.isUpperCase(ca)) {
potition = abcMa.indexOf(String.valueOf(ca));
result.append(String.valueOf(abcMa.get(potition + 13)));
}else if (Character.isLowerCase(ca)){
potition = abcMi.indexOf(String.valueOf(ca));
result.append(String.valueOf(abcMi.get(potition + 13)));
}else{
result.append(String.valueOf(ca));
}
}
return result.toString();
}
}0respuestas