Advertisement
CreateWithChirag

Detect Capital - Java

Jan 3rd, 2023
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | Source Code | 0 0
  1. class Solution {
  2.     public boolean detectCapitalUse(String word) {
  3.       int n = word.length();
  4.       int count =0; //uppercase
  5.  
  6.       for(int i =0; i <n;i++){
  7.           if(Character.isUpperCase(word.charAt(i))){
  8.               count++;
  9.           }
  10.       }
  11.  
  12.       //cases
  13.       if(count == n || count ==0){
  14.           return true;
  15.       }
  16.  
  17.       if(Character.isUpperCase(word.charAt(0)) && count ==1){
  18.           return true;
  19.       }
  20.         return false;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement