Page 537 - AP Computer Science A, 7th edition
P. 537
Consider method getCount below:
public static int getCount(String s, String sub) {
int count = 0;
int pos = s.indexOf(sub); while (pos >= 0)
{
s = s.substring(pos); count++;
pos = s.indexOf(sub);
}
return count; }
What will the method call getCount(“a carrot and car”, “car”) return?
(A) 0
(B) 1
(C) 2
(D) 3
(E) No value returned. The method is in an infinite loop.
20. Consider a program that deals with various components of different vehicles. Which of the following is a reasonable representation of the relationships among some classes that may comprise the program? Note that an open up-arrow denotes an inheritance relationship and a down-arrow denotes a composition relationship.
19.