J.P. Morgan interview question

a programming question based on java