Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.127 :

Posted: Mon Jan 16, 2012 7:18 pm
by Daan Debie
I'm confused by this part of the question:

Code: Select all

System.out.printf("\"%,d\"", i2);
in which

Code: Select all

int i2 = 2222;
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? :)

Re: About Question com.enthuware.ets.scjp.v6.2.127 :

Posted: Mon Jan 16, 2012 9:53 pm
by admin
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.

Re: About Question com.enthuware.ets.scjp.v6.2.127 :

Posted: Tue Jan 17, 2012 12:20 pm
by Guest
But why does the "+" flag exist, if it prints the sign anyways?

Re: About Question com.enthuware.ets.scjp.v6.2.127 :

Posted: Tue Jan 17, 2012 12:34 pm
by admin
+ flag exists to print the sign even if the number is positive. If you don't use +, only negative number will have the sign.

Re: About Question com.enthuware.ets.scjp.v6.2.127 :

Posted: Wed Jan 18, 2012 11:33 am
by Daan Debie
Thanks for clearing that up!

Re: About Question com.enthuware.ets.scjp.v6.2.127 :

Posted: Sun Dec 02, 2012 8:43 am
by Guest
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

Code: Select all

"-2 222"


we use space instead of comma so the question is: can we assume that program is run on EN local?

Re: About Question com.enthuware.ets.scjp.v6.2.127 :

Posted: Sun Dec 02, 2012 9:13 am
by admin
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

Code: Select all

"-2 222"


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.

Re: About Question com.enthuware.ets.scjp.v6.2.127 :

Posted: Sun Dec 02, 2012 1:35 pm
by Guest
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 :)

Re: About Question com.enthuware.ets.scjp.v6.2.127 :

Posted: Sun Dec 02, 2012 2:03 pm
by Guest
I have just read what I wrote and it does not make sense. Too much testes. I will switch my JVM into US Local :)