본문 바로가기

Coding Test/프로그래머스

[프로그래머스/자바] 숫자 문자열과 영단어

 

class Solution {
    public int solution(String s) {
        String[] words = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
        
        for(int i = 0; i < words.length; i++){
            s = s.replace(words[i], Integer.toString(i));
        }
        
        return Integer.parseInt(s);
    }
}