@@ -0,0 +1,868 @@
+package codingbat.string2;%0A%0A/*%0A * Return true if the string %22cat%22 and %22dog%22 appear the same number of times %0A * in the given string. %0A * %0A * catDog(%22catdog%22) = true%0A * catDog(%22catcat%22) = false%0A * catDog(%221cat1cadodog%22) = true%0A * %0A */%0A%0Apublic class CatDogTest %7B%0A%0A  public static void main(String%5B%5D args) %7B%0A%0A    CatDogTest test = new CatDogTest();%0A%0A    System.out.println(%22%3E%22 + test.catDog(%22catdog%22) + %22%3C%22);%0A    System.out.println(%22%3E%22 + test.catDog(%22catcat%22) + %22%3C%22);%0A    System.out.println(%22%3E%22 + test.catDog(%221cat1cadodog%22) + %22%3C%22);%0A  %7D%0A%0A  public boolean catDog(String str) %7B%0A    int cats = 0;%0A    int dogs = 0;%0A%0A    for (int i = 0; i %3C str.length() - 2; i++) %7B%0A      %0A      if (str.substring(i, i + 3).equals(%22cat%22)) %7B%0A        cats += 1;%0A      %7D%0A      else if (str.subSequence(i, i + 3).equals(%22dog%22)) %7B%0A        dogs += 1;%0A      %7D%0A    %7D%0A%0A    return cats == dogs;%0A  %7D%0A%0A%7D%0A

add task catDog