Solved problem 19 (Java helped a lot)