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.

Help with Square Shaped Spiral

I am currently working an Assignment that involves creating a square shaped spiral using loops. I thought I'd figure it out but I found out that the right side of the square spiral is not drawing a line.. Any ideas on how to fix this.. Thanks a lot you guys.

P.S. I uploaded a picture of my output, if you guys could please look at it to know what I'm talking about or you could instead copy and run the code on your computers ... Thanks for your help..

Re: Help with Square Shaped Spiral

If you reduce your for loop to a single pass ( i < 1 ), you'll see that you're drawing 4 lines each pass when you should be drawing 5. (Kinda obvious without reducing the loops, but it helped me see what was going on.)

Add the 5th line, and you'll get the desired result. The 5th line is the 3rd line of the for loop shifted 20 to the right of center rather than 20 to the left of center.