forked from varunu28/LeetCode-Java-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetect Capital.java
More file actions
26 lines (26 loc) · 941 Bytes
/
Detect Capital.java
File metadata and controls
26 lines (26 loc) · 941 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
public class Solution {
public boolean detectCapitalUse(String word) {
boolean capitalFirst = Character.isUpperCase(word.charAt(0));
if (word.length() > 1) {
boolean capitalSec = Character.isUpperCase(word.charAt(1));
for (int i=1;i<word.length();i++) {
if (capitalFirst && capitalSec) {
if (Character.isUpperCase(word.charAt(i)) == false) {
return false;
}
}
else if (capitalFirst && capitalSec == false) {
if (Character.isUpperCase(word.charAt(i)) == true) {
return false;
}
}
else {
if (Character.isUpperCase(word.charAt(i)) == true) {
return false;
}
}
}
}
return true;
}
}