Pregunta de entrevista de IBM

Two java programs are given in Hackerrank test