public class Solution {
public int solution(int n) {
int answer = 0;
String strN = String.valueOf(n);
int c;
for (int i = 0; i < strN.length(); i++) {
c = strN.charAt(i) - 48;
answer += c;
}
return answer;
}
}
'프로그래머스' 카테고리의 다른 글
프로그래머스 - 이상한 문자 만들기 (0) | 2019.01.10 |
---|---|
프로그래머스 - 평균 구하기 (0) | 2019.01.09 |
프로그래머스 - 문자열 내림차순으로 배치하기 (0) | 2019.01.09 |
프로그래머스 - 소수 찾기 (0) | 2019.01.09 |
프로그래머스 - 약수의 합 (0) | 2019.01.09 |