카테고리 없음

프로그래머스: 숫자 문자열과 영단어

Daeryuk Kim 2024. 1. 20. 16:48
class Solution {
    public int solution(String s) {
        String[] arr = {"zero","one","two","three","four","five","six","seven","eight","nine"};
        
         for(int i=0;i<arr.length;i++) {
        	if(s.contains(arr[i])) {
        		s = s.replace(arr[i], Integer.toString(i));
        	}
        }
        return Integer.parseInt(s);
    }
    public static void main(String[] args) {
        
        String s = "one4seveneight";
        
        Solution sol = new Solution();
        int result = sol.solution(s);
     
        System.out.println(result); 
        
    }
}