Added the Java solution to problem 4.