- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3136.java
29 lines (27 loc) · 960 Bytes
/
_3136.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
packagecom.fishercoder.solutions.fourththousand;
importjava.util.Arrays;
importjava.util.HashSet;
importjava.util.Set;
publicclass_3136 {
publicstaticclassSolution1 {
publicbooleanisValid(Stringword) {
if (word.length() < 3) {
returnfalse;
}
Set<Character> vowels =
newHashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));
booleancontainsVowel = false;
booleancontainsConsonant = false;
for (charc : word.toCharArray()) {
if (vowels.contains(c)) {
containsVowel = true;
} elseif (Character.isAlphabetic(c)) {
containsConsonant = true;
} elseif (!Character.isDigit(c)) {
returnfalse;
}
}
returncontainsVowel && containsConsonant;
}
}
}