problem_4 for java