Its cause your spaces. You split the first string into "5 ", and go through both characters. Space is not equal to a number so your valid is set to false. Then it goes to the next loop, and sets...