Not able to take input

do we have to use arraylist in this for 2nd loop?