I ran it with a txt file (I read a file name from the console when I tested it instead) with the following in it: a dkj aa po kk e ??? ? ! The output was: 8 ! 1 a 3 d 1 e 1 j 1 k 3 ? 4 o 1 So it's calculated the frequency correctly, so I'm not sure why that condition hasn't passed. I don't know why it's sorted everything except "?" into ascending order either