-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetectCapital
More file actions
38 lines (38 loc) · 1.15 KB
/
detectCapital
File metadata and controls
38 lines (38 loc) · 1.15 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
class Solution {
public boolean detectCapitalUse(String word) {
String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String lower = "abcdefghijklmnopqrstuvwxyz";
if (word.length() ==1){
return true;
}
if (lower.contains(""+word.charAt(0))){
for(int i = 1;i<word.length();i++){
if (upper.contains(""+word.charAt(i))){
// System.out.print("HERE");
return false;
}
}
return true;
}
else {
// first letter cap and rest not
if (lower.contains(""+word.charAt(1))){
for(int i = 2;i<word.length();i++){
if (upper.contains(""+word.charAt(i))){
// System.out.print("HERE");
return false;
}
}
}
else{
for(int i = 1;i<word.length();i++){
if (lower.contains(""+word.charAt(i))){
// System.out.print("HERE");
return false;
}
}
}
}
return true;
}
}