Its a programming challenge which I am try to do in Java