Added Java implementation of Problem2