Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public boolean detectCapitalUse(String word) {
- if (word == null || word.length() == 0) return true;
- boolean firstUpperCase = Character.isUpperCase(word.charAt(0));
- if (firstUpperCase) { // in this case, all capital or neither capital
- boolean allCapital = true, neitherCapital = true;
- for (int i = 1; i < word.length(); i++) {
- if (Character.isUpperCase(word.charAt(i))) neitherCapital = false;
- else allCapital = false;
- }
- return allCapital || neitherCapital;
- } else { // neither capital!
- for (int i = 1; i < word.length(); i++) {
- if (Character.isUpperCase(word.charAt(i))) return false;
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement