Count Vowels
Completed
Read a line and print how many vowels (a, e, i, o, u - either case) it contains.
Input
One line.
Output
The count.
Example
Input
Hello World
Output
3
Editor
Java
Hints
Loop over the characters with charAt(i).
"aeiou".indexOf(c) >= 0 checks if c is a vowel.
Solution explanation
Lower-casing first means you only have to check five letters.
Show solution
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String line = sc.nextLine().toLowerCase();
int count = 0;
for (int i = 0; i < line.length(); i++) {
if ("aeiou".indexOf(line.charAt(i)) >= 0) {
count++;
}
}
System.out.println(count);
}
}