손코딩
[프로그래머스] 자릿수 더하기 본문
728x90
728x90
import java.util.*;
public class Solution {
public int solution(int n) {
int answer = 0;
while(n >= 1){
answer += n % 10;
n = n/10;
}
return answer;
}
}
'Java' 카테고리의 다른 글
[프로그래머스] 콜라츠 추측 (0) | 2021.01.27 |
---|---|
[프로그래머스] 짝수와 홀수 (0) | 2021.01.27 |
[프로그래머스] 약수의 합 (0) | 2021.01.27 |
[프로그래머스] 수박수박수박수박수박수? (0) | 2021.01.27 |
[프로그래머스] 서울에서 김서방 찾기 (0) | 2021.01.27 |