Sign In

[JAVA] 모음 제거

Created by
  • 무둥
Created at
Category
  1. JAVA
Status
해결
영어에선 a, e, i, o, u 다섯 가지 알파벳을 모음으로 분류합니다. 문자열 my_string이 매개변수로 주어질 때 모음을 제거한 문자열을 return하도록 solution 함수를 완성해주세요.

◇ 내 답변

class Solution { public String solution(String my_string) { String answer = ""; for (int i = 0; i < my_string.length(); i++) { if (my_string.charAt(i) == 'a' || my_string.charAt(i) == 'e' || my_string.charAt(i) == 'i'|| my_string.charAt(i) == 'o'|| my_string.charAt(i) == 'u') { continue; } else { answer += my_string.charAt(i); } } return answer; } }
1.
뭔가 열받

◇ 다른 답변

class Solution { public String solution(String my_string) { String answer = ""; answer = my_string.replaceAll("[aeiou]", ""); return answer; } }
다른 사람 코드.
1.
replaceAll(a, b) 는 a를 b로 대체하는 메소드
2.
[aeiou]는 정규표현식 중 하나. 저 중 하나에 해당하는 모든 문자를 뜻함.