Page 1227 - AP Computer Science A, 7th edition
P. 1227

19. (E) The first value of pos is 2, the index of the first occurrence of “car” in “a carrot and car”. Then s gets assigned “carrot and car” and pos is now 0. Since pos is not advanced, it is stuck with a value of 0 and the method has an
infinite loop. Notice that you can fix this problem by changing
s=s.substring(pos); to s=s.substring(pos+1);
































































































   1225   1226   1227   1228   1229