This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes printf() doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "printf() doubt" Watch "printf() doubt" New topic
Author

printf() doubt

sweety singh
Ranch Hand

Joined: Dec 15, 2007
Posts: 49
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 ]
Murali Kakarla
Ranch Hand

Joined: Jul 11, 2007
Posts: 80
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...
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: printf() doubt
 
Similar Threads
format()
Formatter question
Formatting with printf() and format
Formating with printf() and format()
String formatting doubt