March 29, 2008 3 Comments
Over on his blog, Peter sometimes like to tease people with the odd puzzle or so. Over the Easter holidays, I have been playing with Java Sets a bit and promptly fell into a trap. Now as is usual with these things, particularly if you are somewhat of a Java “noob” like me, it took me a while to figure out what went wrong. And in the spirit of sharing and joint pain, I thought I should do a puzzle too and blog this one……it might keep some of you amused. Here is the little toy programme I was playing with at the time:
(Apologies for the code being in a pic – WordPress messes with the angle brackets) Looks easy enough, right? And I promise you it compiles and runs. Now, without running it, what do you think it prints? Now run it. What does it print? Did you expect what it printed (if so, congratulations…..:-)). If not, what could be the reason?