package codingbat.string2;

/*
 * Return true if the given string contains an appearance of "xyz" 
 * where the xyz is not directly preceeded by a period (.). 
 * So "xxyz" counts but "x.xyz" does not. 
 * 
 * xyzThere("abcxyz") = true
 * xyzThere("abc.xyz") = false
 * xyzThere("xyz.abc") = true
 * 
 */

public class XyzThereTest {

  public static void main(String[] args) {

    XyzThereTest test = new XyzThereTest();

    System.out.println(">" + test.xyzThere("abcxyz") + "<");
    System.out.println(">" + test.xyzThere("abc.xyz") + "<");
    System.out.println(">" + test.xyzThere("xyz.abc") + "<");
  }

  public boolean xyzThere(String str) {
    String word;

    if (str.length() < 3) {
      return false;
    }

    for (int i = 0; i <= str.length() - 3; i++) {
      word = str.substring(i, i + 3);

      if (word.matches("xyz")) {
        if (i > 0 && str.substring(i - 1, i).equals(".")) {
          return false;
        }
        return true;
      }
    }

    return false;
  }

}

@@ -602,16 +602,81 @@
 + %22%3C%22);%0A
+    System.out.println(%22%3E%22 + test.xyzThere(%22abc.xyzxyz%22) + %22%3C%22);%0A
   %7D%0A%0A  p
@@ -728,16 +728,44 @@
 ng word;
+%0A    Boolean hasXYZ = false;
 %0A%0A    if
@@ -901,16 +901,63 @@
 i + 3);%0A
+      %0A//      System.out.println(word);%0A      
 %0A      i
@@ -1048,30 +1048,32 @@
 %7B%0A          
-return
+hasXYZ =
  false;%0A    
@@ -1073,24 +1073,31 @@
 e;%0A        %7D
+ else %7B
 %0A        ret
@@ -1097,21 +1097,35 @@
     
-return
+  hasXYZ =
  true;%0A
+        %7D%0A
     
@@ -1142,26 +1142,27 @@
 %0A    return 
-false
+hasXYZ
 ;%0A  %7D%0A%0A%7D%0A

finish task xyzThere