Page 1 of 1

About Question enthuware.ocpjp.v7.2.1410 :

Posted: Sun May 05, 2013 9:39 am
by RobynBackhouse
What does the 9 do in this line?

Code: Select all

System.out.printf("\"$%(,9.2f\"", -1222.2);
If I change it to a 4
e.g.

Code: Select all

System.out.printf("\"$%(,4.2f\"", -1222.2);
The output is exactly the same. Both output

Code: Select all

"$(1,222.20)"
Thanks.

Re: About Question enthuware.ocpjp.v7.2.1410 :

Posted: Sat May 11, 2013 6:56 am
by admin
That's because the output already has 9 characters. Try 10 or more instead of 9. Then you will see the difference:
System.out.printf("\"$%(,12.2f\"", -1222.2);
HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1410 :

Posted: Tue Oct 22, 2013 9:30 am
by kumarkhiani
With reference to :
System.out.printf("\"%+07d\"", 100); // 7 is the total width. It will print: +000100

Please confirm that we cannot use "-" left justification when we use zero padding. Which means we cannot use "-" and "0" at the same time.

Re: About Question enthuware.ocpjp.v7.2.1410 :

Posted: Tue Oct 22, 2013 10:52 am
by admin
kumarkhiani wrote:With reference to :
System.out.printf("\"%+07d\"", 100); // 7 is the total width. It will print: +000100

Please confirm that we cannot use "-" left justification when we use zero padding. Which means we cannot use "-" and "0" at the same time.
Not sure I understand you correctly. Can you please write a line of code to show what you mean?
-Paul.