Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
Members have full access to the forums. Advertisements are removed for registered users.
Last edited by jps; August 24th, 2013 at 11:13. Reason: code tags
Please post your code in code tags.
Changing the value of the loop control variable, in this case 'j', inside the loop is not a great idea. I recommend that you use another variable to compute the squares and print that, leaving 'j' alone.
Will try that..by the way changing the order of print ( printing at the start of the loop helped too )
I have an explaination for your code.
Your code makes sqaures indeed but what happens is that when the last square is made(i = 7 ; 7 * 7= 49) the loop will stop because j is over 40.
If you want to stop the loop before it goes over 40 then you should use the square before 40 that is 36(6 * 6).
Then you should test what the sqaure is going to be before it is going to print it.
If you have time then using a pen and paper just trace your program line by line.
You shall know what is causing the fault. And you may be able to fix it on your own.