栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验

[单项选择题] 下面程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是 public class FindKeyWords{  public static void m

面试经验 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

[单项选择题] 下面程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是  public class FindKeyWords{   public static void m

[单项选择题] 下面程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是 public class FindKeyWords{  public static void main(String[]args) {   String text="An array is a data structur that stores a collection of"         +"values of the same type. You access each indMdual value"         +"through an integer index. For example,if a is an array"         +"of inergers,then a[i]is the ith integer in the array.";   int arrayCount=0;   int index=-1;   String arrayStr="array";   index=text.indexOf(arrayStr);   while(index>=0) {    ++arrayCount;    index+=arrayStr.length();    index=text.indexOf(arrayStr,index);   }   System.out.println("the text contains"+arrayCount+"arrays");  } }


A.<
B.=
C.<=
D.>=


参考答案:

D

问题解析:

程序中变量index为text.indexOf(arrayStr)的返回值,indexOf方法的原型为:public int indexOf(string str),如果字符串参数作为一个子字符串在此对象中出现,则返回第一个这样的子字符串的第一个字符的索引;如果它不作为一个子字符串出现,则返回-1。public int indexOf(string str,int fromIndex)从指定的索引处开始,返回第一次出现的指定子字符串在此字符串中的索引,如果没有指定字符串出现,则返回-1。本程序是判断子字符串是否出现,因此判断结果>=0即可。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/261949.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号