Created the solution to Problem 3 in Java.