• 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 wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

printf confusion

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i can't seem to get the hang of printf. how did you guys memorize all the combinations?

Also



...do we always need to have d in the end?





 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
following are the characters those are required for outputting specific type of values
d for integers
b for booleans
s for strings
c for character and
f for float

and yes we have to give those character for respective values because the compiler gives error at runtime
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that's right.
First have a look to the easiest printf.
All what you need is a % and a letter described above.


or


Then you can add other signs.

Do you want to have less digits after the dot, use

and so on
$1 : use the first parameter
 
Creator of Enthuware JWS+ V6
Posts: 3412
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can check the API documentation:
Java5API
and choose the class java.io.PrintStream.printf(String format, Object... args)
If you have read that, go further on the format section: format string format
Regards,
Frits
 
reply
    Bookmark Topic Watch Topic
  • New Topic