import java.util.Scanner;
public class Copy {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("请在下边输入你要检测的字符,按enter结束");
String y = s.next();
String a = "asdf";
int t=0;
for (int i = 0; i <a.length(); i++) {
String b = a.substring(i,i+1);
if(b.equals(y)){
t++;
}
}
System.out.println("在字符串中,"+y+"被包含了"+t+"次");
}
}
温馨提示:答案为网友推荐,仅供参考