Created the solution to Problem 2 in Java.