public static void main(String[] args) throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("输入字符串:");
String str1 = in.readLine();
System.out.print("输入字符:");
String str2 = in.readLine();
char ch = str2.charAt(0);
System.out.println("字符是"+ch);
int count=0;
for(int i=0;i<str1.length();i++)
{
if(ch==str1.charAt(i))
count++;
}
System.out.println("字符"+ch+"出现了"+count+"次");
}
// 楼上用split的那个方法,在str只有s的情况下就错了
温馨提示:答案为网友推荐,仅供参考