-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprblm3136.java
More file actions
38 lines (34 loc) · 1.1 KB
/
prblm3136.java
File metadata and controls
38 lines (34 loc) · 1.1 KB
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
36
37
38
public class prblm3136 {
public static void main(String[] args) {
String word = "234Adas";
System.out.println(new prblm3136().isValid(word));
String word2 = "b3";
System.out.println(new prblm3136().isValid(word2));
String word3 = "a3$e";
System.out.println(new prblm3136().isValid(word3));
}
public boolean isValid(String word) {
if (word.length() < 3) {
return false;
}
boolean hasVowel = false, hasConsonant = false;
boolean[] check = new boolean[26];
for (char ch: "aeiou".toCharArray()) {
check[ch - 'a'] = true;
}
for (char ch : word.toCharArray()) {
if (Character.isAlphabetic(ch)) {
if (check[Character.toLowerCase(ch) - 'a']) {
hasVowel = true;
}
else{
hasConsonant = true;
}
}
else if(!Character.isDigit(ch)){
return false;
}
}
return hasVowel && hasConsonant;
}
}