https://school.programmers.co.kr/learn/courses/30/lessons/12926
class Solution {
public String solution(String s, int n) {
StringBuilder answer = new StringBuilder();
char[] arr = s.toCharArray();
for (int i = 0; i < s.length(); i++) {
if (arr[i] == ' ') { // ๊ณต๋ฐฑ ๊ตฌ๋ณ
answer.append(" ");
} else if (Character.isLowerCase(arr[i])) { // ๋์๋ฌธ์ ๊ตฌ๋ณ (์๋ฌธ์์ผ๋)
if (arr[i] + n > 'z') {
answer.append((char) (arr[i] + n - 26)); // n๋งํผ ๋ฐ์ด์ ๋ค๋ฅธ ์ํ๋ฒณ์ผ๋ก ๋ฐ๊ฟ
} else {
answer.append((char) (arr[i] + n));
}
} else { // ๋๋ฌธ์์ผ๋
if (arr[i] + n > 'Z') {
answer.append((char) (arr[i] + n - 26));
} else {
answer.append((char) (arr[i] + n));
}
}
}
return answer.toString();
}
}