-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetectCapital.java
More file actions
39 lines (36 loc) · 1.09 KB
/
DetectCapital.java
File metadata and controls
39 lines (36 loc) · 1.09 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
public class Solution {
public boolean detectCapitalUse(String word) {
if(word == null || word.length() == 0){
return true;
}
//If first character is UPPER CASE, then all remaining must be either all lower or all upper case.
if(Character.isUpperCase(word.charAt(0))){
return isUpperCase(word) || isLowerCase(word);
}
//If first character is lower case, then all remaining must be lower case.
if(Character.isLowerCase(word.charAt(0))){
return isLowerCase(word);
}
return false;
}
public boolean isUpperCase(String word){
int i = 1;
while(i < word.length()){
if(!Character.isUpperCase(word.charAt(i))){
return false;
}
i++;
}
return true;
}
public boolean isLowerCase(String word){
int i = 1;
while(i < word.length()){
if(!Character.isLowerCase(word.charAt(i))){
return false;
}
i++;
}
return true;
}
}