• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to align mutliple columns properly using print?

 
beu curt
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
Chrome Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds like a job for printf()!
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
beu curt wrote: . . . I can't make the column straight . . .
I managed it
 
beu curt
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
beu curt
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 12100
30
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:

try this:


It stopped the error but it did not align the elements. Thank you
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic