aspose file tools*
The moose likes Beginning Java and the fly likes How to align mutliple columns  properly using print? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to align mutliple columns  properly using print?" Watch "How to align mutliple columns  properly using print?" New topic
Author

How to align mutliple columns properly using print?

beu curt
Greenhorn

Joined: Jan 16, 2010
Posts: 18
Hello



The values are in double. How can attain that format?
Thak you very much.
LOL I can't make the column straight But what I am trying to do is align all the elements.
David Coons
Greenhorn

Joined: Feb 07, 2011
Posts: 6

This sounds like a job for printf()!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39869
    
  28
beu curt wrote: . . . I can't make the column straight . . .
I managed it
beu curt
Greenhorn

Joined: Jan 16, 2010
Posts: 18
I'm still not able to align the elements.

Here is what I am doing


If the answer to equation exceeds place value compare to the element on its side, it messes up the pattern.
When I tried to use %f it gave me an error.



I managed it

Did you use printf?


fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11480
    
  16

When I tried to use %f it gave me an error.

How exactly did you try using %f? What was your code?

And what EXACTLY was the error?

We can't help you fix what was wrong if you don't tell us.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
beu curt
Greenhorn

Joined: Jan 16, 2010
Posts: 18

Here is what I am trying



Here is my error






What I am trying do is align all the elements regardless of the place value.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11480
    
  16

I am not an expert with Java's printf, but have used C's.

the %f is sort of like a method argument.

if table[r][c] is the value you want to print in place of the %f, don't use the '+' character, but a comma:


try this:
beu curt
Greenhorn

Joined: Jan 16, 2010
Posts: 18
fred rosenberger wrote:

try this:


It stopped the error but it did not align the elements. Thank you
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11480
    
  16

note that normally, you specify what teh format should be. for example,

"%6.2f" will (i believe) force a 6 character wide number with two to the right of the decimal point. Have you read up on how to use printf?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to align mutliple columns properly using print?