This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
hi, i have an array of objects only when i print to the screen if any of the names have 6 or more charcters in it when it prints out, all those over 6 characters make the next colum move to the right, so they are not all nested neatly under each others. Does any one have any idias how to solve this?
Martyn...<br /> <br />SCJP 1.4 SCWCD 1.4
Tempora Telora
Ranch Hand
Joined: Jun 20, 2005
Posts: 83
posted
0
post your code please.
Martyn Clark
Ranch Hand
Joined: Apr 16, 2005
Posts: 108
posted
0
hi here is the code for print out:
System.out.println("Student name\tStudent course"); System.out.println("------------\t--------------"); for (int i = 0; i < store.getSize(); i++) { System.out.println(i + 1 + store.retrieveList(i).getName()+ "\t\t" + store.retrieveList(i).getCourse()); }
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
The tab character spaces over to the next multiple of 8 plus 1. So a short name spaces over to 9, a longer name spaces over to 17. (Some environments use values other than 8, eg your editor might use 4.)
I'd probably solve this by picking a length to use for all names and manually padding with spaces. Something like this will do:
name = (name + TEN_SPACES).substring(0, 10); println( name );
The second or third time I had to do it, I might want to make a set of generic padding methods:
I based my methods on the REXX language, which has very nice syntax. Google for "rexx left" or "rexx right" for examples. [ June 29, 2005: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Martyn Clark
Ranch Hand
Joined: Apr 16, 2005
Posts: 108
posted
0
Thanks for that stan, i will do a search and check it out.