单选题
下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是( )。publicclassFindKeyWordspublicstaticvoidmain(Sting[]args)Stingtext="Anarrayisadatastructurthatstoresacollectionof"+"valuesofthesametype.Youaccesseachindividualvalue"+"throughanintegerindex.Forexample,ifaisanarray"+"ofinergers,thena[i]istheithintegerinthearray.";intarrayCount=0;intindex=-1:StingarrarStr="array":index=text.indexof(arrayStr):While(index ??______??0)++arrayCount;index+=arrayStr.length();index=text.indexof(arrayStr,index);System.out.println("thetextcontains"+arrayCount+"arrays");
【正确答案】
D
【答案解析】while循环首先计算终止条件,当布尔表达式(termiantion)的值为true时,循环执行大括号中的语句。若某次判断其值为false,则结束循环。若首次计算条件就不满足,循环体中的语句一次都不会被执行。indexof(string)方法返回字符串中字符串string在父串中首次出现的位置,从0开始!没有返回-1;方便判断和截取字符串。所以程序中只有当index>=0时才会执行while循环。