Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817
Moderator: admin
Daan Debie
Post
by Daan Debie » Mon Jan 16, 2012 7:18 pm
I'm confused by this part of the question:
in which
My answer was: "2,222"
Correct answer should be: "-2,222"
The explanation states:
"+" Include a sign (+ or -) with this argument - Applicable only if conversion char is d or f (i.e. for numbers).
There is however no "+" within the string to be formatted! Why should the answer include a sign then?
admin
Site Admin
Posts: 10386 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Mon Jan 16, 2012 9:53 pm
In the code given with the question, i2 = -2222; therefore the given answer is correct.
The explanation is only giving you information about the formatting options that you need to know for the exam.
HTH,
Paul.
Guest
Post
by Guest » Tue Jan 17, 2012 12:20 pm
But why does the "+" flag exist, if it prints the sign anyways?
admin
Site Admin
Posts: 10386 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Tue Jan 17, 2012 12:34 pm
+ flag exists to print the sign even if the number is positive. If you don't use +, only negative number will have the sign.
Daan Debie
Post
by Daan Debie » Wed Jan 18, 2012 11:33 am
Thanks for clearing that up!
Guest
Post
by Guest » Sun Dec 02, 2012 8:43 am
in this example
Code: Select all
int i2 = -2222;
System.out.printf("\"%,d\"", i2);
correct anwser is "-2,222".
But I think it depends on Local. I run this on my JVM which is located in Poland and me answer is
we use space instead of comma so the question is: can we assume that program is run on EN local?
admin
Site Admin
Posts: 10386 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Sun Dec 02, 2012 9:13 am
Guest wrote: in this example
Code: Select all
int i2 = -2222;
System.out.printf("\"%,d\"", i2);
correct anwser is "-2,222".
But I think it depends on Local. I run this on my JVM which is located in Poland and me answer is
we use space instead of comma so the question is: can we assume that program is run on EN local?
That is a good question. We have seen questions on the real exam that explicitly tell you to assume EN US as the locale. However, the problem with such questions is that international candidates may not have any idea about the conventions used in EN US.
On the other hand, there are question where the default locale is not specified either and in this case, the answer may be different for each candidate.
So the lesser of the two evils is to assume EN US as the locale if it is not specified explicitly in the question because the test is administered from the US.
HTH,
Paul.
Guest
Post
by Guest » Sun Dec 02, 2012 1:35 pm
maybe it would be a good idea to set local in your app into US and do not depends on a local from JVM. It makes me stats worse
Guest
Post
by Guest » Sun Dec 02, 2012 2:03 pm
I have just read what I wrote and it does not make sense. Too much testes. I will switch my JVM into US Local
Users browsing this forum: Bing [Bot] and 8 guests