Pregunta de entrevista de Amdocs

asked to solve a Java program