Page 1 of 1
About Question enthuware.ocpjp.v7.2.1619 :
Posted: Mon Jul 22, 2013 5:10 pm
by renatumb
The program worked on the wrong way. I had answered right but it gave "You answered incorrectly".
Re: About Question enthuware.ocpjp.v7.2.1619 :
Posted: Mon Jul 22, 2013 6:51 pm
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.
Re: About Question enthuware.ocpjp.v7.2.1619 :
Posted: Sat Aug 31, 2013 6:03 pm
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 !
Re: About Question enthuware.ocpjp.v7.2.1619 :
Posted: Sun Sep 01, 2013 7:04 am
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.
Re: About Question enthuware.ocpjp.v7.2.1619 :
Posted: Sun Sep 01, 2013 10:01 am
by sinapse
"The ordinary index starts with the first format specifier that does not use explicit index."
This your statement !
Re: About Question enthuware.ocpjp.v7.2.1619 :
Posted: Sun Sep 01, 2013 11:40 am
by admin
Yes, this is as per JavaDoc API description given here:
http://docs.oracle.com/javase/7/docs/ap ... atter.html
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1619 :
Posted: Sun Sep 01, 2013 12:57 pm
by sinapse
Can you explain to me this statement ?
I can't understand it..
Re: About Question enthuware.ocpjp.v7.2.1619 :
Posted: Sun Sep 01, 2013 1:18 pm
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.