Need help for explaination
<p>I need some explaination for this code. 
This is the example code given by others.</p>

<pre><code>    for ( int i = 1; i &lt;= 8; i++ )
    {
        if(check % 2 == 0)
            sum += i;
        else
            sum -= i;
        check /= 2;            &lt;--- Need explanation for this line.
    }
</code></pre>

<p>But in the <code>Pseudo code</code>, there is no <code>"check /= 2;"</code> procedure.</p>

<p>Here is the full <code>Pseudo code</code>.</p>

<pre><code>int binary = 0;
int sum;

while(binary&lt;256)
sum = 0;
for(go through all 8 digits)
    if the i-th digit is 0
        sum += i
    if the i-th digit is 1
        sum -= i
end for

if sum == 0
    output

binary++
end while
</code></pre>

<p>So, what is the purpose for that line of code?</p>

<p>Since <code>sum</code>, <code>binary</code>, and <code>check</code> is initialize as <code>0</code>.</p>

<p>I have written this code using the Pseudocode given above.
But seems like my code will duplicate the output and one more problem, the format.</p>

<p>I want the output be like this format : </p>

<pre><code>Enter a number : 3

-1 -2 +3 = 0
1 +2 -3 = 0 
</code></pre>

<p>But my currently output is :</p>

<pre><code>Enter a number : 3

-1 -2 3 = 0
1 2 -3 = 0
</code></pre>

<p>Here is my code : </p>

<pre><code>CODE IS REMOVED!
</code></pre>

<p>Solved!</p>

<p>I'm too focus on the <code>for</code>-loop for the output part, hence miss the <code>while</code>-loop for the binary, because the pseudocode is for 256 possible solutions, hence, there will be same output for the front part, example :</p>

<pre><code>1 - 2 - 3 + 4 = 0                             

1 - 2 - 3 + 4 + 5 - 6 - 7 + 8 = 0
</code></pre>

<p>Hence, the pseudocode may give an same output. So, since the solution is in <code>2 ^ n</code> where <code>n = 1, 2, 3, ...</code> form, so change the</p>

<pre><code> while( binary &lt; 256 )   ---&gt;     while ( binary &lt; Math.pow(2, input))
</code></pre>

<p>should solve it.</p>

<p>The format and the duplicate of the answer are solved.
Thanks for the helps from all.</p>

<p><code>Remark : I am a Java newbie and stackoverflow newbie, any mistakes please correct me. Thanks.</code></p>
