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

14. (E) Suppose s contains “cat”. You want pigString = “at” + “c” + “ay”. Now the string “at” is the substring of s starting at position 1 and ending at position s.length()–1. The correct substring call for this piece of the word is s.substring(1,s.length()), which eliminates choices A, C, and D. (Recall that the first parameter is the starting position, and the second parameter is one position past the last index of the substring.) The first letter of the word—”c” in the example —starts at position 0 and ends at position 0. The correct expression is s.substring(0,1), which eliminates choice B.


































































































   909   910   911   912   913