aspose file tools*
The moose likes Beginning Java and the fly likes How To Use Formatted Printing i.e. printf() ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How To Use Formatted Printing i.e. printf() ?" Watch "How To Use Formatted Printing i.e. printf() ?" New topic
Author

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

Vishal Kashyap
Ranch Hand

Joined: Aug 07, 2010
Posts: 73

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.

MCSA 2003 | Preparing For OCPJP/SCJP6
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Vishal Kashyap
Ranch Hand

Joined: Aug 07, 2010
Posts: 73

Thanks Wouter ,

Definitely I'll try your suggestion of Coffee....... First.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39854
    
  28
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

Joined: Aug 07, 2010
Posts: 73

Thanks Ritchie Sir.........Glad to know my mistakes.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39854
    
  28
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.
 
wood burning stoves
 
subject: How To Use Formatted Printing i.e. printf() ?