강의

멘토링

커뮤니티

Inflearn Community Q&A

ganada5541609's profile image
ganada5541609

asked

Introduction to Java Algorithm Problem Solving: Coding Test Preparation

9. Extract numbers only

replaceAll을 이용해서 풀어도 괜찮을까요??

Written on

·

238

0

안녕하세요 강사님!

이전 강의에서 배운  replaceAll 을 이용해서 푸는 방법은

강의에서 알려주신 방법보다 덜 효율적인지 궁금합니다!

public class Main {

   public int solution(String str){
      int answer = 0;
      
      str = str.toUpperCase().replaceAll("[A-Z]", "").replaceAll("[a-z]", "");

      answer = Integer.parseInt(str);

      return answer;
   }

   public static void main(String[] args) {
      Main T = new Main();
      Scanner sc = new Scanner(System.in);
      String str = sc.nextLine();
      System.out.println(T.solution(str));
   }

}
java코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

잘 하신 코드입니다. 좋은데요^^

ganada5541609's profile image
ganada5541609

asked

Ask a question