Java Queen Solution