Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public class Solution {
  2. public boolean detectCapitalUse(String word) {
  3. if (word == null || word.length() == 0) return true;
  4. boolean firstUpperCase = Character.isUpperCase(word.charAt(0));
  5. if (firstUpperCase) { // in this case, all capital or neither capital
  6. boolean allCapital = true, neitherCapital = true;
  7. for (int i = 1; i < word.length(); i++) {
  8. if (Character.isUpperCase(word.charAt(i))) neitherCapital = false;
  9. else allCapital = false;
  10. }
  11. return allCapital || neitherCapital;
  12. } else { // neither capital!
  13. for (int i = 1; i < word.length(); i++) {
  14. if (Character.isUpperCase(word.charAt(i))) return false;
  15. }
  16. }
  17. return true;
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement