title: How to run for loop in java?
body: <p>I would like to know why this code do not run. Is there something missing?</p>
  
  <p>Count the number of <code>"xx"</code> in the given string. We'll say that overlapping is allowed, so <code>"xxx"</code> contains 2 <code>"xx"</code>.</p>
  
  <pre><code>public class Drumkit {
      int countXX(String str){
          String a = "abcxxx";
          int count = 0;
          for (int i = 0; i &lt; str.length() - 1; i++) {
              if (a.substring(i, i + 2).equals("xx")) count++;
          }
          return count;
      }
  }
  </code></pre>