Algorithm/백준[JAVA]
[백준] 1264번 : 모음의 개수[JAVA]
코린이 김투덜
2024. 5. 4. 23:39
https://www.acmicpc.net/problem/1264
1264는 아주 쉬운 문제였다.
# 문제
# 접근방식
- 'a', 'e', 'i', 'o', 'u'의 수를 세는 함수 만들기(대문자 또는 소문자이기 때문에 대문자도 고려해야함)
- while()문을 써서 "#"입력시 종료되도록 하기
# 소스코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static int cntVowels(String str) {
int count = 0;
for (int i = 0; i < str.length(); i++) {
if ((str.charAt(i) == 'a') || (str.charAt(i) == 'e') || (str.charAt(i) == 'i') || (str.charAt(i) == 'o') || (str.charAt(i) == 'u')||
(str.charAt(i) == 'A') || (str.charAt(i) == 'E') || (str.charAt(i) == 'I') || (str.charAt(i) == 'O') || (str.charAt(i) == 'U')) {
count++;
}
}
return count;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String str = br.readLine();
if(str.equals("#")){
break;
}
System.out.println(cntVowels(str));
}
}
}
# 성능
# 회고
'a', 'e', 'i', 'o', 'u'가 대문자 또는 소문자라는 조건을 제대로 안읽고 문제를 풀었다가 한 번 틀렸다..
문제 잘 읽기!