-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetectCapital.java
More file actions
44 lines (41 loc) · 1.07 KB
/
DetectCapital.java
File metadata and controls
44 lines (41 loc) · 1.07 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
39
40
41
42
43
44
class Solution {
public boolean detectCapitalUse(String word) {
if (allLower(word)) {
return true;
} else if (allCapital(word)) {
return true;
} else if (onlyFirstCapital(word)) {
return true;
} else {
return false;
}
}
public boolean allLower(String str) {
for (char c : str.toCharArray()) {
if (Character.isUpperCase(c)) {
return false;
}
}
return true;
}
public boolean onlyFirstCapital(String str) {
char first = str.charAt(0);
if (Character.isLowerCase(first)) {
return false;
}
for (int i = 1; i < str.length(); i++) {
if (Character.isUpperCase(str.charAt(i))) {
return false;
}
}
return true;
}
public boolean allCapital(String str) {
for (char c : str.toCharArray()) {
if (Character.isLowerCase(c)) {
return false;
}
}
return true;
}
}