
public class StringOps {
  
  
  public static void main(String[] args) { 
    String word = "Hello, how are you?";
    
    int howMany = count(word, 'a');
    
    System.out.println("There are "+howMany+" a's in \""+word+"\"");
    
    int index = word.indexOf('e');
    System.out.println("The first e is at index "+index);
    
    index = word.indexOf('z');
    if(index==-1) {
      System.out.println("There are no z's in the word");
    }else{
      System.out.println("The first z is at index "+index);
    }
    
    index = word.indexOf("are");
    System.out.println("\"are\" can be found starting at index "+index);
    
    index = word.lastIndexOf('e');
    System.out.println("The last e is at index "+index);
    
    
    String smaller = word.substring(3, 11);
    System.out.println("\""+smaller+"\"");
    
    smaller = word.substring(11);
    System.out.println("\""+smaller+"\"");
    
    
    int cutIndex = word.indexOf("are");
    String firstPart = word.substring(0, cutIndex);
    String endPart = word.substring(cutIndex+3);
    word = firstPart + "is" + endPart;
    
    System.out.println(word);
    
  }
  
  public static int count(String word, char letter) {
    
    int total=0;
    for(int i=0; i<word.length(); i++) {
      char current = word.charAt(i);
      if(current==letter) {
        total++;
      }
    }
    
    return total;
  }
  
  public static void printAfterSpace(String str) {
   int index = 0;
   
   int indexOfSpace = str.indexOf(" ", index);
   
   while(indexOfSpace != -1 && str.length()-indexOfSpace>=3) {
     String twoLetters = str.substring(indexOfSpace+1, indexOfSpace+3);
     System.out.println(twoLetters);
     index = indexOfSpace+1;
     indexOfSpace = str.indexOf(" ", index);
   }
   
   
   int index = str.indexOf(" ");
   while(index != -1 && str.length()>=2) {
    str = str.substring(index+1);
    String twoLetters = str.substring(0,2);
    index = str.indexOf(" ");
   }
     
     
     
   }
  }
 
  
}
