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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Daan Debie

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

Post 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? :)

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Guest

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

Post by Guest »

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:

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

Post 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.

Daan Debie

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

Post by Daan Debie »

Thanks for clearing that up!

Guest

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

Post 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?

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Guest

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

Post 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 :)

Guest

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

Post 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 :)

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests