单选题 Java
题号 #2243903

下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是(  )。
public class FindKeyWords(
public static void main(sring[]args){
sting text=
"An array is a data structur that stores a eollection of"
+"values of the same type.You access each individu-
al value"
+"through an integer index.For example.if a is an
array"
+"of inergers,then all]is the ith integer in the ar-
ray.";
Int arrayCount=0;
Int idex=-l;
Sting arrarStr="array":
Index=text.indexof(arrayStr);
While(index       0){
++arrayCount:
Index+=arrayStr.1ength(); 
Index=text.indexof(arrayStr,index);
}
System.OUt.println
("the text contains"+arrayCount+"arrays");
}
}

进入在线模考

参考答案

D

答案解析

D。【解析】在字符串中查询指定的字符或子串,可用indexof()方法,如查询成功,返回所查字符的位置。如不成功,返回-l,从下面程序可以看出,While条件应为查询成功。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考