/** 12/3/2018
  A String variable sentence consists of words separated by single spaces.
  Write the Java code needed to print the number of words that start with an 
  upper case letter. So for "The deed is done", your code would print 1 but 
  for "The name is Bond, JAMES Bond", your code would print 4. 
***/

import java.util.Scanner;

public class SampleFinalQ3 {
  public static void main(String[] args) {
    // PART A
    String sentence = "The name is Bond, JAMES Bond."; 
    System.out.println(sentence);
    int count = 0;
    // iterate through the words in sentence
    int loc = -1;
    // use a do-while assuming that I have at least one word in sentence
    do {
    // check if word has uppercase, count it
       if(Character.isUpperCase(sentence.charAt(loc+1)))
           count++;
       // modify loc to be next space
       loc = sentence.indexOf(' ', loc+1);
    } while (loc!=-1);
    
    System.out.println("count: " + count);
    // PART B
    // An int variable n contains a positive integer and a String variable s 
    // contains a String. Write the Java code needed to print "YES" if the 
    // first n characters of s appear more than once in s, and print "NO" 
    // otherwise.
    String answer = "YES", s="aab";
    int n=2;
    for (int i=0; i<n; i++) {
      if (s.substring(i+1).indexOf(s.charAt(i))==-1 &&
                          s.substring(0,i).indexOf(s.charAt(i))==-1)
            answer="NO";
    }
    System.out.println(answer);     
  }
}