백준 Baekjoon 10987번 모음의 개수 - JAVA

Jaeho Kim·2022년 4월 22일
0

코딩테스트

목록 보기
79/110

https://www.acmicpc.net/problem/10987

문제
알파벳 소문자로만 이루어진 단어가 주어진다. 이때, 모음(a, e, i, o, u)의 개수를 출력하는 프로그램을 작성하시오.

입력
첫째 줄에 단어가 주어진다. 단어의 길이는 1보다 크거나 같고, 100보다 작거나 같으며, 알파벳 소문자로만 이루어져 있다.

출력
첫째 줄에 모음의 개수를 출력한다.

예제 입력 1

baekjoon

예제 출력 1

4
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);

		String str = sc.nextLine();

		int count = 0;
		for (int i = 0; i < str.length(); i++) {
			char t = str.charAt(i);
			if (t == 'a' || t == 'e' || t == 'i' || t == 'o' || t == 'u')
				++count;
		}
		System.out.println(count);
		sc.close();
	}
}
  • 설명
profile
Hello, World!

0개의 댓글