IBM interview question

Two java programs are given in Hackerrank test