Added Java solution for Problem F.

Tested with input files.