Solve problems 31,34,39 using Java.