Solve problem 125 using Java.