About Question enthuware.ocpjp.v7.2.1619 :

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

Moderator: admin

Post Reply
renatumb
Posts: 47
Joined: Mon Apr 08, 2013 7:55 pm
Contact:

About Question enthuware.ocpjp.v7.2.1619 :

Post by renatumb »

The program worked on the wrong way. I had answered right but it gave "You answered incorrectly".
Attachments
Screen Shot 2013-07-22 at 7.07.22 PM.png
Screen Shot 2013-07-22 at 7.07.22 PM.png (41.26 KiB) Viewed 3616 times

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

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

Post by admin »

There was a problem with this question. Two options were set as correct options. It was updated recently. If you took the test before the update and if you review the test after the update, it can cause this weird situation.

It has been fixed now and should not happen again.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

sinapse
Posts: 27
Joined: Sat Aug 31, 2013 5:38 pm
Contact:

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

Post by sinapse »

The explanation is wrong:

The ordinary index starts with the first format specifier that does not use explicit index.

In this case, it starts with the middle %s. Therefore, it prints the first argument which is A.

This is not true in my opinion in fact if u use:

System.out.printf("%2$s %s %<s", "A", "B", "C");

it prints : B A A

while is was supposed to print : A B B according to the explanation !

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

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

Post by admin »

No, the explanation is correct and your statement prints as per the explanation.
First, it prints 2$s, which means B (because you are specifying the index explicitly here).
then you have %s without explicit index, which mean the ordinary indexing will start now with 1 and so it prints A.
Finally, you have %<s. At this point the ordinary index is 2, but because of <, it will print the value at 1. So it prints A.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

sinapse
Posts: 27
Joined: Sat Aug 31, 2013 5:38 pm
Contact:

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

Post by sinapse »

"The ordinary index starts with the first format specifier that does not use explicit index."

This your statement !

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

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

Post by admin »

Yes, this is as per JavaDoc API description given here: http://docs.oracle.com/javase/7/docs/ap ... atter.html

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

sinapse
Posts: 27
Joined: Sat Aug 31, 2013 5:38 pm
Contact:

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

Post by sinapse »

Can you explain to me this statement ?
I can't understand it..

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

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

Post by admin »

I can certainly try to explain but the link that I gave above would give you a more complete picture.

What it means is that when the format specifier doesn't use any index explicitly then the compiler assumes that it is using "ordinary index". This ordinary index starts from 1 and applies to the first format specifier that doesn't use explicit index.

In this case, i.e. in "%2$s %s %<s", you see there are 3 format specifiers
1. %2$s <-- this one specifies explicit index 2. Therefore, ordinary index will not apply here.
2. %s <--this one does not specify any explicit index. Therefore, ordinary index will Start with 1 from here.
and 3. %<s <--this one does not specify any explicit index either. Therefore, ordinary index will be increment (because it already started earlier) used here, which is 2 now. But it also has <, so it will use the previous ordinary index, which was 1.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 50 guests