Created the solution to Problem 6 in Java.