solve 2.3, 2.4, Java