[프로그래머스] 자릿수 더하기

[프로그래머스] 자릿수 더하기

public static String solution(int s) { String[] split = String.valueOf(s).split(""); int answer = 0; for(String a : split) { answer += Integer.valueOf(a); } return answer; }

여기서 생각해보아야 할 것은!

public int solution(int n) { int answer = 0; while(true){ answer+=n%10; if(n<10) break; n=n/10; } // [실행] 버튼을 누르면 출력 값을 볼 수 있습니다. System.out.println("Hello Java"); return answer; }

from http://cayahuh10.tistory.com/61 by ccl(A) rewrite - 2021-12-19 12:28:25