Java string puzzle