Wednesday, July 1, 2009

Puzzle 37 – Solution

Thanks everyone for the Birthday wishes - it was great getting so many greetings!

The String class has an intern() method. The intern() method makes sure that if Strings are equal then it returns the same string. Read up on the intern() for more information.

package com.twisters;
class Stingify{
public static void main(String args[]){
String firstOne
= new String("Happy Birthday").intern();
String secondOne
= new String("Happy Birthday").intern();
/* No change to the line below! */
"First String is equal to second : " + (firstOne == secondOne));

I did offer a bonus point for anyone who came up with more than one solution so for those of you did get in more than one solution the bonus point is on!

Sebastian came up with what I suspect is almost all possible solutions to this puzzles. I would check out his solutions - specially the one he marked out as favorite. Its my favorite too -:).

No comments:

Post a Comment

Solution for this question?