I tried searching and couldn't find anything, so I'm sorry if this has been posted before. I need help aligning output at the command line. I want to make even columns, but can't figure out how to do it.

Attached is a screenshot of my current output. I want the code to automatically handle the alignment for nodes 10 and 11, and triple digit numbers if it got that high, and so on and so forth. Is there an output stream class or anything like that that would help me with this?

Recommended Answers

All 3 Replies

I tried searching and couldn't find anything, so I'm sorry if this has been posted before. I need help aligning output at the command line. I want to make even columns, but can't figure out how to do it.

Attached is a screenshot of my current output. I want the code to automatically handle the alignment for nodes 10 and 11, and triple digit numbers if it got that high, and so on and so forth. Is there an output stream class or anything like that that would help me with this?

It's been a while for me, but I imagine NumberFormat might be helpful, as well as printf from the Console class.


http://java.sun.com/docs/books/tutorial/i18n/format/numberintro.html
http://java.sun.com/javase/6/docs/api/java/text/NumberFormat.html
http://java.sun.com/javase/6/docs/api/java/io/Console.html

Thank you, I believe that will help.

I have used "\t" to tab over to a lined up position. That could be an option for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.