• 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

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.......i have doubt in formatting

int i1 = -123;
int i2 = 12345;

System.out.printf(">%0,7d< \n", i2);
System.out.format(">%+-7d< \n", i2);

result is

>012,345<
>+12345 <

can you explain me this......how did the comma go between 012 and y the - symbol was not inserted....

thanks...
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The - symbol was not printed since you are printing a positive integer (i2 is greater than zero)
and when the comma symbol is used to format the numbers, typically comma separates group of 3 digits from the RHS. Thus, 1234567 will be printed as 1,234,567
 
shilpa Reddy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply...but i din get the concept of i2 greater than zero....
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use the - symbol , if you're printing a negative number .. it'll be printed inside parenthesys



result is

>(5355)<

Hope this helps...
 
shilpa Reddy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that happens when you use "(" this symbol..... - will jus insert - i guess
 
Rodolfo Velasco
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oo.. thanks..
is good to know..

 
reply
    Bookmark Topic Watch Topic
  • New Topic