@@ -0,0 +1,1051 @@
+package codingbat.string2;%0A%0A/*%0A * We'll say that a String is xy-balanced if for all the 'x' chars %0A * in the string, there exists a 'y' char somewhere later in the string. %0A * So %22xxy%22 is balanced, but %22xyx%22 is not. One 'y' can balance multiple 'x's. %0A * %0A * Return true if the given string is xy-balanced. %0A * %0A * xyBalance(%22aaxbby%22) = true%0A * xyBalance(%22aaxbb%22) = false%0A * xyBalance(%22yaaxbb%22) = false%0A * %0A */%0A%0Apublic class XYBalanceTest %7B%0A%0A  public static void main(String%5B%5D args) %7B%0A%0A    XYBalanceTest test = new XYBalanceTest();%0A%0A    System.out.println(%22%3E%22 + test.xyBalance(%22aaxbby%22) + %22%3C%22);%0A    System.out.println(%22%3E%22 + test.xyBalance(%22aaxbb%22) + %22%3C%22);%0A    System.out.println(%22%3E%22 + test.xyBalance(%22yaaxbb%22) + %22%3C%22);%0A  %7D%0A%0A  public boolean xyBalance(String str) %7B%0A    boolean balanced = true;%0A    %0A    for(int i=0; i%3Cstr.length(); i++)%7B%0A      if(str.substring(i, i+1).equals(%22x%22))%7B%0A        balanced = false;%0A      %7D%0A      else if(!balanced && str.substring(i, i+1).equals(%22y%22))%7B%0A        balanced = true;%0A      %7D%0A    %7D%0A    %0A    return balanced;%0A  %7D%0A%0A%7D%0A

add task xyBalance