Java Program to solve a riddle