Java code for CodeEval