Pergunta de entrevista da empresa IBM

Two java programs are given in Hackerrank test