62,614
社区成员
发帖
与我相关
我的任务
分享
package com.keeya.util;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
HelloWorld1 hello = new HelloWorld1();
System.out.println(hello.countSubstring());
}
}
class HelloWorld1 {
public int countSubstring() {
String p = "abababa";
String c = "a";
int sum = 0;
int len = p.length();
for (int i = 0; i < len; i++) {
if (Character.toString(p.charAt(i)).equals(c)) {
sum++;
}
}
return sum;
}
}