P166: Added Java solution.
P345: Added Java solution.