
public class Fall2017FinalQ3 {
  
  
  public static void main(String[] args) { 
    String word = "The name is Bond James Bond";
    String copy = new String(word);
    int n=3;
    System.out.println(countCapitals(word));
    
    String firstPart = word.substring(0, n);
    
    System.out.println(word==copy);
    System.out.println(word.equals(copy));
    
    word.compareTo("Hello");
    
    /*word.compareTo(sentence)
     * 
     * returns 0 if word.equals(sentence)
     * returns >0 if word > sentence
     * returns <0 if word < sentence
     */
    /*lhs < rhs -> lhs.compareTo(rhs) < 0
     * lhs <= rhs -> lhs.compareTo(rhs) <=0
    word.indexOf(firstPart, 1) == -1? "NO" : "YES";
    
    word.lastIndexOf(firstPart)==0 ? "NO": "YES";
    */
    
    
    
  }
  
  public static int countCapitals(String sentence) {
   int count=0;
   
   if(Character.isUpperCase(sentence.charAt(0)))
     count++;
   
   int index = sentence.indexOf(" ");
   
   while(index!= -1) {
     
    sentence = sentence.substring(index+1);
    
    if(Character.isUpperCase(sentence.charAt(0)))
      count++;
    
    index = sentence.indexOf(" ");
  }
   
   return count;
     
}
  
}
