자바/알고리즘
프로그래머스 숫자 문자열과 영단어
OverTheHorizon3410
2021. 12. 29. 01:57
프로그래머스
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | package test; /* */ public class lv1숫자_문자열과_영단어 { public static void main(String[] args) { String s = "one4seveneight"; Solution2 solution2 = new Solution2(); solution2.solution(s); } } class Solution2 { public int solution(String s) { String[] words = new String[]{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; for (int i = 0; i < words.length; i++) { s = s.replaceAll(words[i], String.valueOf(i)); } System.out.println("s = " + s); return Integer.parseInt(s); } } | cs |