When the number is just one digit long (the numbers below 10), the loop doesn't execute even once, because string.length() will be 1, and if you divide that by 2 it becomes 0 (because of integer division).
Since k starts at 0, which is not < 0, the condition in the for will be false and the loop won't be executed.
i found a solution but i dont like it much. i changed lines 10 and 21
for(int k = 0; k < string.length() / 2; k++)
for(int k = 0; k <= string.length() / 2; k++)
and lines 18 and 29
if(k == (string.length() / 2) - 1)
if((k == (string.length() / 2) - 1) || (string.length() == 1))