/** Problem: You are given a string which we call text, 
  * and a pattern, report first occurrence of a repetition of 
    the pattern. For example, if the pattern is "abc" report the 
    first occurrence of "abcabc" if it occurs. */

import java.util.Scanner;

public class StringRepeats {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String text = "AAGTAAGAAGAAGGCTTTAACCTTAAAGGGTTTAACACATATATATAT";
    String motif = "AAG";
    
    String repeat = motif.concat(motif);
    int loc = text.indexOf(repeat);
    if (loc != -1)
        System.out.println(repeat + " found at location " + loc); 
    // another way of doing the same thing  
    // this code finds all occurrences of the repeated motif
    loc = text.indexOf(motif);
    while (loc!=-1)  {
         // is it followed by another motif?
         int loc2 = text.indexOf(motif, loc+motif.length());
         if (loc2 == loc+motif.length())
             System.out.println(repeat + " found at location " + loc); 
         loc = loc2;
    }
   
    StringBuilder msg = new StringBuilder("See you at the designated spot.");
    for (int i=0; i<msg.length(); i++) {
      // convert character to lowercase first and then encode
         char lowerCh = Character.toLowerCase(msg.charAt(i));
         msg.setCharAt(i, (char)(lowerCh+2));
    }
    System.out.println("msg is now: " + msg);
    
  }
}