본문 바로가기
코딩테스트 연습/프로그래머스 Lv.0

프로그래머스 코딩테스트 lv.0 - 문자열 정수의 합. 자바/JAVA

by 트레비봄 2023. 8. 23.
728x90
문제 설명

소스 코드
class Solution {
    public int solution(String num_str) {
        int answer = 0;
        
        String[] str = num_str.split("");
        for(int i = 0; i < str.length; i++){
            answer += Integer.parseInt(str[i]);
        }
        return answer;
    }
}

split, 형변환에 익숙해지자

728x90