Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Archives
Today
Total
관리 메뉴

KSI일기장

프로그래머스 숨은 숫자 덧셈1(자바) 본문

JavaAlgorithm

프로그래머스 숨은 숫자 덧셈1(자바)

MyDiaryYo 2023. 11. 27. 16:27

 

 

 

 

class Solution {
    public int solution(String my_string) {
        
        //영어 잘라버리기
        String ms = my_string.replaceAll("[a-zA-Z]", "");
        
        //숫자만 남아있는 String을 배열로 변환
        String[] arr = ms.split("");
        
        //총합
        int answer = 0;
        for(int i=0; i<arr.length; i++){
        //Integer.parseInt(arr[i]) == Integer.valueOf(arr[i])
            answer += Integer.parseInt(arr[i]); 
        }
        return answer;
    }
}