P171: Added Java solution.