Created the solution to Problem 5 in Java.