• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printf confusion

 
Bhaarat Sharma
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • 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?





 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
 
Michael Hilgert
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2437
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic