solve 3.4-3.5, Java