Solve problem 57 using Java.