프로그래머스 문자열 정수의 합

박철현·2023년 5월 17일

프로그래머스

목록 보기
12/80

프로그래머스 - 문자열 정수의 합

class Solution {
    public int solution(String num_str) {
        int answer = 0;
       String[] strArray = num_str.split("");
        for(int i =0; i<strArray.length; i++) {
            answer += Integer.parseInt(strArray[i]);
        }
        return answer;
    }
}
  • .split("") : 하나씩 분리
  • .subString(i, i+1)도 가능함
profile
비슷한 어려움을 겪는 누군가에게 도움이 되길

0개의 댓글