solve 2.2, Java