• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To Use Formatted Printing i.e. printf() ?

 
Vishal Kashyap
Ranch Hand
Posts: 73
BSD C++ Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a confusion regarding formatted printing i.e. printf().

Basically, as I know printf() is more powerful and handy to use . But, I know here,

%d is used for integer.
%s is used for String.
%f is used for float.

But, what about double, boolean, long, short, etc . I mean to say, Do you have any link regarding complete detail about printf() usage? Please provide me complete detail or any link if you have.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is all defined in the Format String Syntax which can be found here. It is fairly complicated so get a good cup of coffee before reading it.
 
Vishal Kashyap
Ranch Hand
Posts: 73
BSD C++ Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Wouter ,

Definitely I'll try your suggestion of Coffee....... First.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not quite. %d is for a decimal integer and %f for a fixed-point fraction.

There are simple introductions in the Java™ Tutorials here and here.
 
Vishal Kashyap
Ranch Hand
Posts: 73
BSD C++ Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ritchie Sir.........Glad to know my mistakes.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome The other letters don't work quite as easily; %b is obvious and %x is quite easy to work out, but %a doesn't appear to stand for anything I can see.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic