Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
My question about Format
Maggie Zhou
Greenhorn
Posts: 26
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have a question about the printf format
int i = 123; double d = 987.12345; System.out.printf("%2d %1f", i,d)
I thought the code will throw a exception, but the result is :
123 987.123450
why? I can not understand this
Preparing SCJP 6, try to get high score, and looking for a job...
Nikos Pougounias
Ranch Hand
Posts: 110
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
%2d means: Format an integer and display it with at least 2 characters.
%1f means: Format a floating point and display it with at least 1 character.
An exception would be raised if you switched the arguments: %2
$
d %1
$
f
Try it for your self!
Format
string
syntax
[ September 13, 2008: Message edited by: Nikos Pugunias ]
Nikos' Java blog
Maggie Zhou
Greenhorn
Posts: 26
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks a lot! Now I see
Preparing SCJP 6, try to get high score, and looking for a job...
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Calculator program
Dumping the bit values of a primitive type
printf format string question
isNaN function
Can we extend multiple classes ?
More...