Page 1 of 1

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

Posted: Tue Mar 15, 2011 1:45 pm
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.

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

Posted: Wed Mar 16, 2011 7:22 am
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.

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

Posted: Thu Apr 05, 2012 9:50 am
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.

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

Posted: Thu Apr 05, 2012 1:27 pm
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.