 <p>You are getting all 1s because the loop initialization statement <code>int c= x*y</code> will be executed only once for a <code>for</code> loop. That is it is executed the first time when <code>x=1</code> and <code>y=1</code> and since, it is given as the loop initialisation statement and not in the loop body, it is never reevaluated. The for loop works as :</p> <p>The loop initialisation statement is executed only once at the beginning of the loop. After each iteration the loop update expression is executed and the loop condition is reevaluated. <code>for(loop_initialisation;loop_condition;loop_update) { ... }</code></p> <p>So you should update <code>c</code> inside the loop, something like :</p> <pre><code>for ( int c= x*y; y&lt;= 12; y++) { c = x*y; System.out.print(c + " "); } </code></pre>