-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidWord.java
More file actions
28 lines (21 loc) · 778 Bytes
/
Copy pathvalidWord.java
File metadata and controls
28 lines (21 loc) · 778 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
class Solution {
private final List<Character> VOWELS = Arrays.asList('A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u');
public boolean isValid(String word) {
if (word.length() < 3) return false;
boolean vowelExists = false;
boolean consonenetExists = false;
for (char ch : word.toCharArray()) {
if(!(Character.isLetter(ch) || Character.isDigit(ch))) {
return false;
} else if (Character.isLetter(ch)) {
if (VOWELS.contains(ch)) {
vowelExists = true;
} else {
consonenetExists = true;
}
}
}
return vowelExists && consonenetExists;
}
}
//Solved