Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difficulty in following Devakas practice exam Question 7 Practice Exam 1 -

 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the repeat post, but when i was submitting my post after preview, all my code formatting was being dropped, and my text cut short.

I understand pattern and matcher design, however looking at the following question from Devakas SCJP 5.0 exam (Q 7 practice exam 1), Im having difficulty following the conditional logic.

The Question:What will be the result of running and compiling the following code?
Answer: Prints "Hal"



Any one offer any insight (particularly on the conditional logic). Devakas explanation is far from satisfactory.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Steve ,

I worked out like this..


The first call sets the Patern to H[a-b][k-m]
The second call sets the Matcher object
The third call finds the pattern using Matcher find() method and matches "Hal" in Hallo
group() method is used to gather the returned info from find().


 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Balu,

I got it now, I was having an issue with the null return types, but since the object references are never called, apart from the obj 3 which actually is a returned match group, so no worries. Its a sticky question though:

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its a sticky question though:


Absolutely..
 
Fritz Guerilus
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have 2 questions about this:

1. Why does the method have the 2nd String Var-arg argument? It doesn't look to me like it's doing anything.
2. Inside the method:

how does this statement work?
st.pt1=((Pattern)ob).compile(s[0])
Isn't the 1st argument of the method passing the pattern, and then we're casting it into a Pattern and invoking the compile method again

Any help on understanding the logic would be helpful

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic