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

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

Moderator: admin

Post Reply
fuss

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

Post by fuss »

The command is:

Identify the hex numbers that will be captured if the input is ...

Code: Select all

0x
is NOT a valid hex number .

So the correct answer should be:

Code: Select all

None of these.

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

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

Post by admin »

Hi,
The problem statement has been updated as "Identify the tokens that will be captured if the input is ..."

thanks for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.

Pierluigi
Posts: 8
Joined: Thu Feb 23, 2012 5:33 am
Contact:

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

Post by Pierluigi »

Hello,

I didn't understand why does the parser find only 0x ??
I thought this:

given the input string from the question,
"0x12 0x 0 x3abc ab23 0Xfm"

then (starting from index 0)
1) Required 0 -> Found "0"
Required x -> found "x"
Attempt for (digit | smallAlpha | bigAlpha) -> found "1"
So at this point the first captured (and consumed) token should be 0x1.

Then it rejects the "2" and " " until it finds "0" again.
2) "0x" (it also reads a " "(space) which doesn't match with [0-9a-fA-F]?, but since this is terminated
by the '?' quantifier it moves on to the next match);

3) Finally, by the same principle it should find "0Xf".

To sum up, it should find "0x12", "0x" and "0Xf". I also tried to execute this search in a program and it matches my description.

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

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

Post by admin »

I just wrote a program to test this:

Code: Select all

public class TestClass {
    public static void main(String[] args) {
        Pattern p = Pattern.compile("0[xX][0-9a-fA-F]?");
        String input= "0x12 0x 0 x3abc ab23   0Xfm";
        Matcher m = p.matcher(input);
        while(m.find()){
            System.out.println(input.substring(m.start(), m.end()));
        }
    }
}
This prints: 0x1
0x
0Xf

So, it seems the given answer is correct because 0x1 and 0xf are not in the options. Can you please share how are you testing it?

thank you,
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: No registered users and 28 guests