This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
There are a couple of different ways to do this, but one simple one is just to have an extra variable that counts the number of items used in a line so far. At the top of the loop, check the value; when it gets to three, print a newline and the heading, and set the counter back to zero. At the bottom of the loop, add one to the counter.
You need to be careful at the very beginning and the very end: you want to print the header even though there is no previous line, and you don't want to print an extra header if the last line has three items in it. Do this with some extra "if" conditions.
Posted by Erenst Friedman-Hill or the very similar
But as Ernest Friedman-Hill says, there is still a risk of problems with the last line of printing.[/edit 13th August] [edit2]I have lost the bit I quoted from Ernest Friedman-Hill. Sorry. It should have read, "have an extra variable that counts the number of items"[/edit2 14th August] [ August 14, 2006: Message edited by: Campbell Ritchie ]
Joined: Aug 13, 2006
You point me to the right direction. Now I could print out