Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
Members have full access to the forums. Advertisements are removed for registered users.
Last edited by jps; August 24th, 2013 at 11:13 AM. 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.