프로그래머스 숨어있는 숫자의 덧셈(1)

김덕근·2023년 1월 9일
0

algorithm

목록 보기
9/12

toUpperCase(), replaceAll(), split(), Integer.praseInt()

class Solution {
    public int solution(String my_string) {
        int answer = 0;

        String str = my_string.toUpperCase().replaceAll("[A-Z]", "");
        String[] arr = str.split("");

        for(int i = 0; i < arr.length; i++) {
            answer += Integer.parseInt(arr[i]);
        }

        return answer;
    }
}
profile
안녕하세요!

0개의 댓글