-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChallenge07.java
More file actions
35 lines (29 loc) · 779 Bytes
/
Challenge07.java
File metadata and controls
35 lines (29 loc) · 779 Bytes
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
35
package challenge07;
import static org.junit.Assert.assertTrue;
import java.util.regex.Pattern;
import org.junit.Test;
/**
* The Class Challenge06.
*
* count number of vowels and consonants in a String.
*/
public class Challenge07 {
public static String vowelAndConstantCount(String input) {
int vowels = 0;
int constants = 0;
for (int i = 0; i < input.length() - 1; i++) {
if (Pattern.matches("[a-zA-Z]{1}", input.substring(i, i + 1))) {
if (Pattern.matches("[a,e,i,o,u]{1}", input.substring(i, i + 1))) {
vowels++;
} else {
constants++;
}
}
}
return vowels + ";" + constants;
}
@Test
public void test() {
assertTrue("3;7".equals(Challenge07.vowelAndConstantCount("{Programming")));
}
}