国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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ù)的評論 (共 條)

分享到微博請遵守國家法律
丰台区| 汕尾市| 嘉兴市| 鲜城| 屏南县| 巴马| 万全县| 丰顺县| 江阴市| 昂仁县| 成都市| 宜兰市| 福安市| 凭祥市| 永宁县| 临西县| 烟台市| 大埔县| 巴青县| 航空| 永安市| 兰考县| 大竹县| 蒲城县| 双江| 集贤县| 无为县| 莆田市| 峡江县| 长乐市| 浠水县| 新化县| 永城市| 原阳县| 平武县| 西乡县| 绥江县| 罗甸县| 韶山市| 金华市| 河东区|