Solve problem 42 using Java.