| | |
toString format help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Dear god. this is driving me crazy. I'm working on an assignment involving inheritence, multiple classes, etc. I'm stuck at one stupid part. I have to write a toString method that formats the text. Is there a way to return a string with formatted text? I know about the printf method, and I can get that to work fine, but just with System.out.printf... I don't know how to return a formatted string.. Is it even possible?
What i need is I have someones name, first and last, then their age, but the ages of the people have to line up in a column. Make sense? The names & ages are one object, & the multiple people are in array of people objects... so i have a for loop that will go through and print each person one at a time. So how do i pad the age correctly & return it to the calling method?
I would just say forget returning the string and just simply print it out, but I need the same method elsewhere to write to a file also.
so, what i need to end up with is something that looks like this
[html]
Name Age other stuff more stuff
-------------------------------------------------------------------------------
Bob Someguy 42 blabado 3.14
Guy Two 38 dododod 1234
[/html]
nice neat columns n' stuff...
I appreciate any thoughts...
What i need is I have someones name, first and last, then their age, but the ages of the people have to line up in a column. Make sense? The names & ages are one object, & the multiple people are in array of people objects... so i have a for loop that will go through and print each person one at a time. So how do i pad the age correctly & return it to the calling method?
I would just say forget returning the string and just simply print it out, but I need the same method elsewhere to write to a file also.
so, what i need to end up with is something that looks like this
[html]
Name Age other stuff more stuff
-------------------------------------------------------------------------------
Bob Someguy 42 blabado 3.14
Guy Two 38 dododod 1234
[/html]
nice neat columns n' stuff...
I appreciate any thoughts...
BLAH! Ok, i should've done a search first. I found my answer.
For anyone else who need's help on this same thing, here's the thread I found:
http://www.daniweb.com/techtalkforum...ad.php?t=56466
For anyone else who need's help on this same thing, here's the thread I found:
http://www.daniweb.com/techtalkforum...ad.php?t=56466
![]() |
Similar Threads
- How to split datetime format? (ASP.NET)
- file input problems (with windows?) (Java)
- how can i format a text field value with commas in a numeric amount. (JavaScript / DHTML / AJAX)
- How to control decimal poit (ASP.NET)
- class toString() functionality in C++ ...? (C++)
- exporting iMovie Document to Vcd format (Mac Software)
- dates (Visual Basic 4 / 5 / 6)
- Convert a Flash page to PDF format? (Graphics and Multimedia)
Other Threads in the Java Forum
- Previous Thread: help me please..
- Next Thread: help again with textfields
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint 2dgraphics android api apple applet application applications arguments array arrays automation bank binary bluetooth chat class classes client code collision component database db development draw eclipse eclipsedevelopment error event exception file fractal game givemetehcodez graphics gui helpwithhomework homework html ide image input integer integration j2me jarfile java javadesktopapplications javafx javaprojects jmf jni jpanel julia learningresources linux list loop map method methods mobile netbeans newbie number object oracle print problem program programming project projectideas recursion researchinmotion scanner screen server service set size sms socket sort sorting sql sqlserver state string swing swt tcp test text-file threads time tree web windows





