[프로그래머스]숨어있는 숫자의 덧셈

박예림·2023년 3월 6일
0

코테

목록 보기
38/132

class Solution {
    public int solution(String my_string) {
        int answer = 0;
        my_string = my_string.replaceAll("[^0-9]","");//숫자를 제외하고 공백으로 바꾼다.
        
        for (int i=0; i<my_string.length(); i++){
            answer += Integer.parseInt(String.valueOf(my_string.charAt(i)));
        }
        
        return answer;
    }
}
profile
응애 나 아기개발자

0개의 댓글