Amdocs interview question

asked to solve a Java program