-
Notifications
You must be signed in to change notification settings - Fork 0
/
12VowelCount.java
34 lines (28 loc) · 920 Bytes
/
12VowelCount.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* Description: Using the Java language, have the function VowelCount(str)
* take the str string parameter being passed and return the number of vowels
* the string contains (ie. "All cows eat grass" would return 5). Do not count
* y as a vowel for this challenge.
*/
import java.util.*;
import java.io.*;
class Function {
String VowelCount(String str) {
str = str.toLowerCase();
Integer 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') {
count++;
}
}
str = count.toString();
return str;
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
Function c = new Function();
System.out.print(c.VowelCount(s.nextLine()));
}
}