In your While loop, you increment your "left" integer too early. Therefore, when you check the character at left, it will be out of range. Just place your increment operator - "left++;" - at the end...