This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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: 74360
334
  • 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: 13013
66
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: 13013
66
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: 13013
66
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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic