package com.tarena.fly;
/**
* \* Created with IntelliJ IDEA.
* \* User: 武健
* \* Date: 2018/1/29
* \* Time: 20:45
* \* To change this template use File | Settings | File Templates.
* \* Description:String 字符串 指定字符出现次数
* \
*/
public class Main {
public static void main(String[] args) {
String str = "HelloWorld";
String key = "o";
int count = 0;
while (str.indexOf(key) > 0) {
count = count + 1;
str = str.substring(str.indexOf(key) + 1, str.length());
}
System.out.println(count);
}
}
package com.tarena.fly;
/**
* \* Created with IntelliJ IDEA.
* \* User: 武健
* \* Date: 2018/1/29
* \* Time: 20:45
* \* To change this template use File | Settings | File Templates.
* \* Description:String 字符串 指定字符出现次数
* \
*/
public class Main {
public static void main(String[] args) {
String str = "HelloWorld";
String key = "o";
int count = 0;
while (str.indexOf(key) > 0) {
count = count + 1;
str = str.replaceFirst(key,"");
}
System.out.println(count);
}
}