알고리즘/백준
백준 10987 모음의 개수
고구마와 감자
2022. 2. 28. 09:20
https://www.acmicpc.net/problem/10987
10987번: 모음의 개수
알파벳 소문자로만 이루어진 단어가 주어진다. 이때, 모음(a, e, i, o, u)의 개수를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
모음으로 미리 ArrayList를 만들어 놓고 contains로 확인하고 카운트를 올려준다.
public class Boj10987_모음의개수 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
List<Character> list = new ArrayList<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
int cnt = 0;
for (int i = 0; i < s.length(); i++) {
if (list.contains(s.charAt(i))) cnt++;
}
System.out.println(cnt);
}
}