【代码分享】统计字符串中字符的出现次数
程序运行时间如下图public class StringTest {
public static void main(String[] args) {
String s = new String("12311123");
int count = 0;
for (int i = 0; is.length(); i++) {
i = s.indexOf("1",i);
if (i == -1) break;
count++;
}
System.out.println("这个字符出现次数为"+count);
}
}
http://cdn.u1.huluxia.com/g4/M00/33/DF/rBAAdl9SNJGAKNjvAAEuZhfh2B0898.png
页:
[1]