• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

printf() doubt

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
code:

int i1 = -123;
int i2 = 12345;
System.out.printf(">%1$(7d< \n", i1); //1
System.out.printf(">%0,7d< \n", i2); //2
System.out.format(">%+-7d< \n", i2); //3
System.out.printf(">%2$b + 1$5d< \n", i1, false);
This produces:
> (123)<
>012,345<
>+12345 <
>false + -123<

// line 2 produces the output >012,345<... how is the comma arranged after three digits.. is it by default... it is not mentioned in the format string also...
and why is line 3 using format method... is it that printf and format can be used interchangeablly

[ February 07, 2008: Message edited by: sweety singh ]

[ February 07, 2008: Message edited by: sweety singh ]
[ February 07, 2008: Message edited by: sweety singh ]
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Page 490 of Bert and Kathy book:

"," Use locale-specific grouping separators....



In Page 489:


The format() and printf() methods were added to java.io.PrintStream in Java 5. These two methods behave exactly the same way, .....



I think this clears your questions.

Murali...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic