/**
* 测试类, 统计字符串中指定字符的数量
* @author Administrator
*
*/
public class Test3 {
public static void main(String[] args) {
String str = "afioawjflasvuhyoiarejtgiopafjlkfkjewoitjasd";
String target = "a";
int count = 0; //计数器
//循环
while(true) {
//查找target下标
int index = str.indexOf(target);
//判断, index
if (index == -1) break;
//计数
count++;
//将已经查找过的部分截取掉
str = str.substring(index+1);
}
// int index = -1;
//
// while((index = (str = str.substring(index+1)).indexOf(target)) != -1) {
// count++;//计数
// }
System.out.println(target + "的个数:" + count);
}
}
08-08
8799
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交