class Solution {
public String solution(String s, int n) {
String answer = "";
char c;
char newC;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
/**
* 대문자
*/
if (c >= 65 && c <= 90) {
newC = (char) (c + n);
if (newC > 90) {
newC -= 26;
}
answer += newC;
/**
* 소문자
*/
} else if (c >= 97 && c <= 122) {
newC = (char) (c + n);
if (newC > 122) {
newC -= 26;
}
answer += newC;
/**
* 공백
*/
} else if (c == 32) {
answer += c;
}
}
return answer;
}
}
딱히 획기적으로 푼 사람은 없었다
'프로그래머스' 카테고리의 다른 글
프로그래머스 - 가운데 글자 가져오기 (0) | 2019.01.08 |
---|---|
프로그래머스 - 문자열을 정수로 바꾸기 (0) | 2019.01.08 |
프로그래머스 - 문자열 다루기 기본 (0) | 2019.01.08 |
프로그래머스 - K번째수 (0) | 2019.01.08 |
프로그래머스 - 모의고사 (0) | 2019.01.07 |