• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How to align mutliple columns properly using print?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 6
Eclipse IDE Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds like a job for printf()!
 
Marshal
Posts: 80870
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?


 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13091
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
reply
    Bookmark Topic Watch Topic
  • New Topic