• 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

formatting, 0 and #

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
i m studying for SCJP 1.5 upgrade and , in formatting, i cannot understand what's the difference between 0 and #, as it seems that they both represents
integer digits.....

anyone could help?

thanks and regards
marco
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
0 means to pad zeros to the output

and # means Argument is represented in an "alternate form." This depends on the conversion type:
%o Non-negative octal values are prepended with a zero ('0').
%x, %X Hexadecimal values are prepended with the prefix "0x" or "0X".
%e, %E, %f The integer portion of the result always ends with a decimal point ('.'), even if the fractional portion is zero.
%g, %G The fractional portion always appears, even if it is zero.
%c If the character is special or unprintable, it is output in an escaped form. The output can be surrounded by single quotes to form a syntactically valid Java character literal.
There is no alternate form for %s, %d, %u, %z[n], and %Z[n]
reply
    Bookmark Topic Watch Topic
  • New Topic