Pregunta de entrevista de Cognizant

Few puzzles to be coded in java.