title: CodingBat sumNumbers
body: <p>For this problem: <a href="http://codingbat.com/prob/p121193" rel="nofollow">http://codingbat.com/prob/p121193</a></p>
  
  <p>I have written this code:</p>
  
  <pre><code>public int sumNumbers(String str) {
    int y = 0;
    int z = 0;
    for (int f4 = 0; f4 &lt; str.length(); f4++) {
      if (Character.isDigit(str.charAt(f4))) {
        for (int f5 = f4; f5 &lt; str.length(); f5++) {
          if (!Character.isDigit(str.charAt(f5))) {
            z = (Integer.parseInt(str.substring(f4, f5)));
            y = y + z;
            f4 = f5 - 1;
            break;
          }
        }
      }
    }
    return y;
  }
  </code></pre>
  
  <p>These are the problems (they aren't code, but it refused to accept my question otherwise):</p>
  
  <pre><code>sumNumbers("abc123xyz") Expected: 123; Returned: 123
  sumNumbers("aa11b33") Expected: 44; Returned: 11
  sumNumbers("7 11") Expected: 18; Returned: 7
  sumNumbers("Chocolate") Expected: 0; Returned: 0
  sumNumbers("5hoco1a1e") Expected: 7; Returned: 7
  sumNumbers("5$$1;;1!!") Expected: 7; Returned: 7
  sumNumbers("a1234bb11") Expected: 1245; Returned: 1234
  sumNumbers("") Expected: 0; Returned: 0
  sumNumbers("a22bbb3") Expected: 25; Returned: 22
  </code></pre>
  
  <p>So to summarize, for some reason my code can't handle more than one number of more than one digit, and I have no idea why. I've been working on this on and off for a while, and while I refuse to look up answers directly, I could really use some help.
  I'm in high school AP Comp. Sci.</p>