byeol2ing 2021. 9. 17. 20:35
반응형

이 문제는 replaceAll 함수를 알면 너무 쉬운 문제였다.

문자를 숫자로

용도 함수
정수(Int) Integer.parseInt
실수(Float) Float.parseFloat
실수(Double) Double.parseDouble
롱(Long) Long.parseLong

 

 

숫자를 문자로

용도 함수
정수(Int) Integer.toString
실수(Float) Float.toString
실수(Double) Double.toString
롱(Long) Long.toString
class Solution {
    public int solution(String s) {
        int answer = 0;
        s =s.replaceAll("zero","0");
        s =s.replaceAll("one","1");
        s =s.replaceAll("two","2");
        s =s.replaceAll("three","3");
        s =s.replaceAll("four","4");
        s =s.replaceAll("five","5");
        s =s.replaceAll("six","6");
        s =s.replaceAll("seven","7");
        s =s.replaceAll("eight","8");
        s =s.replaceAll("nine","9");
        
        answer = Integer.parseInt(s);
        
        return answer;
    }
}
반응형
댓글수0