Encountering problems with integer input in program

The code is running fine if I give a predefined value to the integer n but is encountering problems once I start using the nextInt(); function to input the value.

code link: