用JAVA编程:::接收键盘输入的字符串,使用String类的方法indexOf()来统计该字符串中各个字符出现的

用JAVA编程:::接收键盘输入的字符串,使用String类的方法indexOf()来统计该字符串中各个字符出现的次数。

public class test {
public static void main(String[] args) {
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(is);
try {
System.out.println("源字符串");
String searchFrom = br.readLine();
System.out.println("要查找的子字符串");
String searchBy = br.readLine();
int begin = 0;
int count = 0;
while (searchFrom.indexOf(searchBy) != -1) {
count++;
begin = searchFrom.indexOf(searchBy) + searchBy.length();
searchFrom = searchFrom.substring(begin);
}
System.out.println(count);
} catch (IOException e) {
e.printStackTrace();
}
}
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-07-10
System.out.println (str[i]); //输出以b打头的字母}System.out.println ("请输入字符串:");BufferedReader in=new BufferedReader(new InputStreamReader(System.in));String s=new String(in.readLine());System.out.println ("大写形式:");System.out.println (s.toUpperCase()); //输出大写形式System.out.println ("小写形式:");System.out.println (s.toLowerCase()); //输出小写形式BufferedReader br=new BufferedReader(new InputStreamReader(System.in));String s2=in.readLine();int index=s2.indexOf(' ');String dst1=new String(s2.substring(0,index));String dst2=new String(s2.substring(index+1,s2.length()));本回答被提问者采纳
相似回答