Scroll indicator done
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/81301

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


package com.example.javaproject3.psstudy;

public class Solution81301 {
    public int solution(String s) {
        String[] num = new String[]{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};  // 각 숫자에 대응하는 영단어
        for(int i=0; i<num.length; i++) //  영단어 배열만큼 반복
            s = s.replaceAll(num[i], Integer.toString(i)); // 해당하는 영단어가 문자열에 있다면 원래 숫자로 대체
        return Integer.parseInt(s);
    }

    public static void main(String[] args) {
        Solution81301 solution81301 = new Solution81301();
        System.out.println(solution81301.solution("2three45sixseven"));
    }
}
728x90