Sunday, May 17, 2009

Puzzle 24 – Solution.

The last puzzle brought out so many solutions that I am having a hard time figuring out which one I like best. Here the list of solutions – I am not posting the entire snippet just the relevant line – check the previous (or next) puzzle if you want to have a look at the question!

1. Solution by Joe Smith and Mine:
x = x++; - Yep Joe got me there. I do spend a lot of my time on Java Ranch so many of the puzzle question do in fact stem out from there. Real Java questions turning to Java puzzles.

2. Solution by Bernardomen, Kannan, Stefan - System.out.println("X is : " + --x); - this one is neat and self explanatory.


3. Solution anonymously left - int x = 0-1; Cute isn’t it?


4. Solution by me – int x = -01; - never said anything about the two characters being continuous did I?

That about covers all the solutions – I got. Here is one more answer that I got but it’s not correct. Usually I don’t point out wrong answer – but this one is a bit special – I thought about a similar question a few months back – and tried to figure out the reason why this particular construct (x++--) doesn’t work? Anyone want to attempt a guess on this?

Congrats to
1. Joe Smith
2. Bernardomen

3. Kannan

4. Stefan

5. Anonymous
for getting the right solution

No comments:

Post a Comment

Solution for this question?