File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ package easy ;
2
+
3
+ import java .util .regex .Matcher ;
4
+ import java .util .regex .Pattern ;
5
+
6
+ /**
7
+ * Have the function VowelCount(str) take the str string
8
+ * parameter being passed and return the number of vowels
9
+ * the string contains (i.e. "All cows eat grass and moo" would return 8).
10
+ * Do not count y as a vowel for this challenge.
11
+ */
12
+ public class VowelCount {
13
+
14
+ /**
15
+ * Vowel Count function.
16
+ *
17
+ * @param str input string
18
+ * @return the number of vowels in a string
19
+ */
20
+ private static int vowelCount (String str ) {
21
+ Pattern pattern = Pattern .compile ("[aeiou]" );
22
+ Matcher matcher = pattern .matcher (str );
23
+ int i = 0 ;
24
+ int count = 0 ;
25
+ while (matcher .find (i )) {
26
+ count ++;
27
+ i = matcher .start () + 1 ;
28
+ }
29
+ return count ;
30
+ }
31
+
32
+ /**
33
+ * Entry point.
34
+ *
35
+ * @param args command line arguments
36
+ */
37
+ public static void main (String [] args ) {
38
+ var result1 = vowelCount ("I cannot sleep unless I am surrounded by books." );
39
+ System .out .println (result1 );
40
+ var result2 = vowelCount ("Life itself is a quotation." );
41
+ System .out .println (result2 );
42
+ }
43
+
44
+ }
You can’t perform that action at this time.
0 commit comments