Code not working due to j not having correct scope

http://ide.codingblocks.com/#/s/16378

please see this code and help me.

You can go through this code, I have commented your mistake in code
https://ide.codingblocks.com/#/s/16441