The body of the for loop will never be executed if line.length() >= 3
Otherwise, if line does not contain 'g', then the if branch will not be executed.
The condition will still be tested every time through the loop.
If there is no 'g' then you'll get the behaviour described, the else branch will be executed each time and the result is displaying your original string.
Can you show a working example, along with input and output?
The input string is "that cag moved"
a starts at 3 because every string starts with "that". I'm trying to correct every "g" into a "t", but every time, I only print out "that cag moved". The if statement never executes.