五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Java oop:查找字符"a"在字符串"What happend today"中出現(xiàn)的次數(shù)

2019-12-31 16:40 作者:詩書畫唱  | 我要投稿


//構(gòu)建一個(gè)java程序,查找字符"a"在字符串"What happend today"中出現(xiàn)的次數(shù)。

package a;


public class Student{


public static void main(String[] args) {

? ?







String str="What happend today";


int times = searchstr("a", str); //返回2


System.out.println("字符a在字符串What happend today中出現(xiàn)的次數(shù):"+times); /*times就是次數(shù)的意思*/


}


public? static? int? ?searchstr(String key/*要搜索的關(guān)鍵詞*/, String str/*字符串*/) {


int index = 0;//每次的搜索到的下標(biāo)


int count = 0;//計(jì)數(shù)器

while (( index=str.indexOf(key, index)) != -1) {


index = index + key.length()/*關(guān)鍵詞的長度*/;


count++;

}

return count; /*沒void就要寫return,這是規(guī)定*/





? ? ? ??

? ? }

}



Java oop:查找字符"a"在字符串"What happend today"中出現(xiàn)的次數(shù)的評論 (共 條)

分享到微博請遵守國家法律
赫章县| 靖州| 改则县| 宁国市| 香河县| 鱼台县| 周口市| 安阳市| 绩溪县| 连云港市| 当雄县| 娄烦县| 金沙县| 安塞县| 庆城县| 南溪县| 威海市| 封丘县| 甘南县| 沁源县| 天峻县| 云霄县| 兖州市| 华蓥市| 柞水县| 保康县| 张掖市| 浦城县| 淮滨县| 汝州市| 海伦市| 宜黄县| 阿勒泰市| 中阳县| 屯留县| 西乌珠穆沁旗| 任丘市| 江源县| 老河口市| 吉木萨尔县| 临汾市|