Infosys BPM Interview Question

Write any code that suits you and explain the logic.