Solve problem 19 using Java.