You never use variable "j". You logic here is wrong but it is simple to fix. You know that.