Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817
Moderator: admin
-
RobynBackhouse
- Posts: 23
- Joined: Sun Apr 14, 2013 10:37 am
-
Contact:
Post
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
Thanks.
-
admin
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
-
Contact:
Post
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.
If you like our products and services, please help us by posting your
review here.
-
kumarkhiani
- Posts: 9
- Joined: Sun Aug 25, 2013 2:36 am
-
Contact:
Post
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.
-
admin
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
-
Contact:
Post
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.
If you like our products and services, please help us by posting your
review here.
Users browsing this forum: No registered users and 256 guests