Returning the value that for statement prints
<p>I would like to return all the information as output that the for statement prints.</p>

<p>For instance:</p>

<pre><code>public static int countNumbers(int x) {

    for (int i = 1; i &lt;= x; i++) {
        System.out.println(i);
    }

    return SOMETHING; // This something should be the values for statements prints.
                      // For example, countNumbers(5) returns 12345.
}
</code></pre>

<p>So when I call the method somewhere else, I will get the output.</p>

<p>So:</p>

<pre><code>int output = countNumbers(3);
//output = 123;
</code></pre>

<p>How can this be done?</p>
