문제 & 예시
소스코드
// 자릿수 더하기
public class test14 {
public static void main(String[] args) {
Solution14 sol = new Solution14();
int n = 123;
System.out.println(sol.solution(n));
}
}
class Solution14 {
public int solution(int n) {
int answer = 0;
int temp = 0;
while(n>0) { // 예시
temp = n % 10; // 3
n = n / 10; // 12
answer += temp;
}
return answer;
}
}