Added third solution (java) for problem 3