title: How to tackle the Codingbat String-2 oneTwo challenge?
body: <p>Here is the problem statement:</p>
  
  <blockquote>
    <p>Given a string, compute a new string by moving the first char to come after the next two chars, so "abc" yields "bca". Repeat this process for each subsequent group of 3 chars, so "abcdef" yields "bcaefd". Ignore any group of fewer than 3 chars at the end.</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>// oneTwo("abc") → "bca"
  // oneTwo("tca") → "cat"
  // oneTwo("tcagdo") → "catdog"  
  
  public String oneTwo(String str) {
      String x = "";
      if (str.length() &lt; 3) {
          return "";
          // return empty
      } else if (str.length() == 3) {
          String s = str.substring(1, str.length());
          x = s + str.substring(0, 1);      // last two + first char
      } else if (str.length() &gt; 3) {
          int third = 2;
          // start with the third element index of 2
          for (int i = 0; i &lt; str.length(); i++) {
              if (i == third) {
                  // given three chars substring first char
                  // substring last two chars and add that to x
                  x += (str.substring(third - 1, third + 1) +
                          str.substring(third - 2, third - 2 + 1));
                  third += 3;
                  //work  with this line but why??????
              }
              //third +=3;
              // doesn't work with this line but why???????
  
  
          }// end of for loop
      }
      return x;
      // return modified string x
  }
  </code></pre>
  
  <p>With <code>third +=3</code> inside of if statement work but when I put that outside of if statement I don't get the desired output. I don't really understand why? </p>