프로그래머스 1단계
자릿수 더하기
https://programmers.co.kr/learn/challenges
문제 설명
풀이
public class Solution {
public int solution(int n) {
int answer = 0;
while(n>0) {
answer += n % 10;
n /= 10;
}
return answer;
}
}
'알고리즘 > 프로그래머스 1단계' 카테고리의 다른 글
[프로그래머스] x만큼 간격이 있는 n개의 숫자 (0) | 2022.04.23 |
---|---|
[프로그래머스] 평균 구하기 (0) | 2022.04.23 |
[프로그래머스] 수박수박수박수박수박수? (0) | 2022.04.23 |
[프로그래머스] 서울에서 김서방 찾기 (0) | 2022.04.23 |
[프로그래머스] 가운데 글자 가져오기 (0) | 2022.04.23 |