Solve problem 11 using Java.