title: Java - number in expanded form
body: <p>I have given number and want it to return as a String in expanded form. For example</p>
  
  <pre><code>expandedForm(12); # Should return "10 + 2"
  expandedForm(42); # Should return "40 + 2"
  expandedForm(70304); # Should return "70000 + 300 + 4"
  </code></pre>
  
  <p>My function works for first and second case, but with 70304 it gives this: </p>
  
  <pre><code>70 + 00 + 300 + 000 + 4
  </code></pre>
  
  <p>Here's my code</p>
  
  <pre><code>import java.util.Arrays;
  
  
  public static String expandedForm(int num)
  {
  
    String[] str = Integer.toString(num).split("");
    String result = "";
  
    for(int i = 0; i &lt; str.length-1; i++) {
      if(Integer.valueOf(str[i]) &gt; 0) {
        for(int j = i; j &lt; str.length-1; j++) {
          str[j] += '0';
        }
      }
    }
  
    result = Arrays.toString(str);
    result = result.substring(1, result.length()-1).replace(",", " +");
    System.out.println(result);
  
    return result;
  }
  </code></pre>
  
  <p>I think there's a problem with the second loop, but can't figure out why.</p>